function timeFunc(content, type) {
const date = new Date(content);
const y = date.getFullYear();
let m = date.getMonth() + 1;
m = m < 10 ? '0' + m : m;
let d = date.getDate();
d = d < 10 ? '0' + d : d;
let h = date.getHours();
h = h < 10 ? '0' + h : h;
const minute = date.getMinutes();
const second = date.getSeconds();
if (type === 'date') {
return y + '-' + m + '-' + d;
}
if (type === 'time') {
return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
}
}
timeFunc('1587295219000', 'date'); // 日期
timeFunc('1587295219000', 'time'); // 日期+时间
网友评论