UNPKG

tool-evans

Version:

这是一款卢本伟用了都说好的格式化时间和转义HTML插件

18 lines (17 loc) 516 B
function formatTime(time) { const date = new Date(time) const y = addZore(date.getFullYear()) const m = addZore(date.getMonth() + 1) const d = addZore(date.getDate()) const h = addZore(date.getHours()) const mm = addZore(date.getMinutes()) const s = addZore(date.getSeconds()) return [y, m, d].join('-') + ' ' + [h, mm, s].join(':') } function addZore(n) { return n < 10 ? '0' + n : n } // console.log(formatTime(new Date())); module.exports = { formatTime }