lh-tools
Version:
lh提供了格式化时间、HTMLEscape相关的功能
25 lines (20 loc) • 575 B
JavaScript
//模块化拆分
//格式化时间的方法
function dateFormat(dtStr) {
const dt = new Date(dtStr);
const y = dt.getFullYear();
const m = padZero(dt.getMonth() + 1); //月份从0开始
const d = padZero(dt.getDay());
const hh = padZero(dt.getHours());
const mm = padZero(dt.getMinutes());
const ss = padZero(dt.getSeconds());
return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
}
//补零的方法
function padZero(n) {
return n > 9 ? n : '0' + n;
}
//暴露格式化时间的函数
module.exports = {
dateFormat
}