UNPKG

itheima-zwhy

Version:

提供了格式化时间日期,转换特殊字符,yyds

18 lines 532 B
// 定义格式化时间函数 function dateFormat(dateStr) { const date = new Date(); const y = date.getFullYear(); const m = zeroFill(date.getMonth() + 1); const d = zeroFill(date.getDate()); const hh = zeroFill(date.getHours()); const mm = zeroFill(date.getMinutes()); const ss = zeroFill(date.getSeconds()); return `${y}${m}${d}${hh}:${mm}:${ss}` } // 定义数字补零函数 function zeroFill(n) { return n < 10 ? '0' + n : n } module.exports = { dateFormat }