UNPKG

itheima-tools-gdq

Version:

格式化时间,HTMLEscape的功能

28 lines (18 loc) 473 B
// 定义格式化时间的函数 function dateFormat(dtStr){ const dt = new Date(dtStr) const y = dt.getFullYear() const m = padZero(dt.getMonth() +1) const d = padZero(dt.getDate()) const hh = padZero(dt.getHours()) const mm = padZero(dt.getMinutes()) const ss = padZero(dt.getSeconds()) return `${y}-${m}-${d} ${hh}:${mm}:${ss}` } // 补0 function padZero(n){ return n>9?n:'0'+n } module.exports ={ dateFormat }