function formatDate(time) {
if (time === null) return ‘’;
let date = new Date(time);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
let m = (date.getMonth() + 1), mm = m < 10 ? ‘0’ + m : m;
let d = date.getDate(), dd = d < 10 ? ‘0’ + d : d;
let h = date.getHours(), hh = h < 10 ? ‘0’ + h : h;
let i = date.getMinutes(), ii = i < 10 ? ‘0’ + i : i;
let s = date.getSeconds(), ss = s < 10 ? ‘0’ + s : s;
return date.getFullYear() + “-” + mm + “-” + dd + ’ ’ + hh + ‘:’ + ii + ‘:’ + ss;
}
时间格式化精确到秒(年-月-日 时:分:秒)
最新推荐文章于 2024-02-26 15:22:30 发布