emo-itheima-tools
Version:
格式化时间和html escape
17 lines (16 loc) • 413 B
JavaScript
function dateFormat(dateStl){
const dt = new Date(dateStl)
const y = pad(dt.getFullYear())
const m = pad(dt.getMonth()+1)
const d = pad(dt.getDay())
const hh = pad(dt.getHours())
const mm = pad(dt.getMinutes())
const ss = pad(dt.getSeconds())
return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
}
function pad(n){
return n>9?n:'0'+n
}
module.exports = {
dateFormat
}