itheima-tools-wxl
Version:
第一个npm包
14 lines • 417 B
JavaScript
function dateFormat(dateStr){
const dt = new Date(dateStr);
const y = dt.getFullYear();
const m = fillZero(dt.getMonth()+1);
const d = fillZero(dt.getDate());
const hh = fillZero(dt.getHours());
const mm = fillZero(dt.getMonth());
const ss = fillZero(dt.getSeconds());
return `${y}-${m}-${d} ${hh}:${mm}:${ss}`;
}
function fillZero(n){
return n>9?n:'0'+n;
}
module.exports= {dateFormat}