cjlitheima-tools
Version:
提供了格式化时间,HTMLEscape的功能
24 lines (19 loc) • 519 B
JavaScript
//定义格式化时间的函数
function dateFormat(dateStr) {
const dt = new Date(dateStr)
const y = dt.getFullYear()
const m = patZeo(dt.getMonth() + 1)
const d = patZeo(dt.getDate())
const hh = patZeo(dt.getHours())
const mm = patZeo(dt.getMinutes())
const ss = patZeo(dt.getSeconds())
return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
}
//定义补零函数
function patZeo(n) {
return n > 9 ? n : '0' + n
}
//暴露成员
module.exports = {
dateFormat
}