// 格式化时间 返回: "2019/01/01 01:02:03" 时间格式
// 传入时间戳:格式化 / 不传参:返回当前时间
function formatTime(timestamp) {
let nowDate;
timestamp ? nowDate = new Date(timestamp) : nowDate = new Date()
let Y = nowDate.getFullYear() + '/';
let M = (nowDate.getMonth() + 1 < 10 ? '0' + (nowDate.getMonth() + 1) : nowDate.getMonth() + 1) + '/';
let D = nowDate.getDate() + ' ';
let h = nowDate.getHours() + ':';
let m = nowDate.getMinutes() + ':';
let s = nowDate.getSeconds();
return Y + M + D + h + m + s;
}
【学习随记】格式化时间
最新推荐文章于 2022-04-20 00:25:25 发布