时间格式转换

console.log(startTime)                       //2018-10-03 00:00:00
console.log(new Date(startTime))             //Wed Oct 03 2018 00:00:00 GMT+0800 (中国标准时间)
console.log(new Date(startTime).getTime())   //1538496000000
console.log(Date.parse(new Date(startTime))) //1538496000000
var numdata=Date.parse(new Date(res.data.data.userDetail.startTime));
console.log(new Date(numdata))               //Wed Oct 03 2018 00:00:00 GMT+0800 (中国标准时间)
var num=new Date(1538496000000);
console.log(change_time(num))                //2018-10-3 0-0-0
function change_time(times){
    return times.getFullYear() + "-" + (times.getMonth() + 1) + "-" + times.getDate() +" " + times.getHours() + "-" + times.getMinutes() + "-" + times.getSeconds() ;
}

 

你可能感兴趣的:(前端,time)