date5_tools
Version:
提供格式化时间、HTMLEscape相关的功能
23 lines (18 loc) • 483 B
JavaScript
// 格式化时间函数
function dateForm(date){
const dt = new Date(date);
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}`;
}
// 补零函数
function padzero(n){
return n>9?n:'0'+n;
}
module.exports={
dateForm
}