UNPKG

hawkingl-util

Version:

提供格式化时间操作、转义HTML的操作、还原HTML的操作

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