function getTimes()
{
var thisDay= new Date();
var year = thisDay.getFullYear(); //年
var month = thisDay.getMonth() + 1; //月
var day = thisDay.getDate(); //日
var hh = thisDay.getHours(); //时
var mm = thisDay.getMinutes(); //分
var ss = thisDay.getSeconds(); //秒
var timer = year + "-";
if(month < 10)
timer += "0";
timer += month + "-";
if(day < 10)
timer += "0";
timer += day + " ";
if(hh < 10)
timer += "0";
timer += hh + ":";
if (mm < 10)
timer += '0';
timer += mm + ":";
if (ss < 10)
timer += '0';
timer += ss;
return(timer);
}
console.log(getTimes())
想要时间戳转日期时间格式的话,直接把时间戳加到 new Date()中就 OK