my-shijian
Version:
提供了格式化时间
25 lines (19 loc) • 557 B
JavaScript
function dateFormat(dateStr) {
//将时间转换成标准时间格式
const dt = new Date(dateStr);
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 = {
dateFormat
};