javascript -- 时间转换

function numFormat(num){
//时间处理
return ('00' + num).substr(-2);    #处理 日期前面有0的情况
}
function timeFormat(timestamp){
//时间处理  2019-10-09 17:11:46
var datetime = new Date(timestamp * 1000);
var year = numFormat(datetime.getFullYear());
var month = numFormat(datetime.getMonth() + 1);
var day = numFormat(datetime.getDate());
var hour = numFormat(datetime.getHours());
var minute = numFormat(datetime.getMinutes());
var second = numFormat(datetime.getSeconds());
return year + '-' + month + '-' + day + '-' + hour + ':' + minute + ':' + second;
}

原文地址:https://www.cnblogs.com/kuku0223/p/11647034.html