function formatDate(date,fmt) {if(/(y )/.test(fmt)){fmt = place(RegExp.$1,(FullYear() '').substr(4-RegExp.$1.length));}let o = {'M ':Month() 1,'d ':Date(),'h ':Hours(),'m ':Minutes(),'s ':Seconds()};// 遍历这个对象for(let k in o){if(new RegExp(`(${k})`).test(fmt)){// console.log(`${k}`)console.log(RegExp.$1)let str = o[k] '';fmt = place(RegExp.$1,(RegExp.$1.length===1)?str:padLeftZero(str));}}return fmt;
};function padLeftZero(str) {return ('00' str).substr(str.length);
}
let TimeNow = 1514374627*1000
let newTime = new Date(TimeNow)
formatDate(newTime,'yyyy-MM-dd hh:mm') //2017-12-27 19:37
本文发布于:2024-02-04 04:55:44,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170699534052245.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |