How to convert milliseconds to date
This question already has an answer here:
You can try this code
//DEFINE THE FUNCTION TO GET DATE FROM MILISECOND
var format = function (time, format) {
var t = new Date(time);
var tf = function (i) { return (i < 10 ? '0' : '') + i };
return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function (a) {
switch (a) {
case 'yyyy':
return tf(t.getFullYear());
break;
case 'MM':
return tf(t.getMonth() + 1);
break;
case 'mm':
return tf(t.getMinutes());
break;
case 'dd':
return tf(t.getDate());
break;
case 'HH':
return tf(t.getHours());
break;
case 'ss':
return tf(t.getSeconds());
break;
}
})
}
//ALERT THE OUTPUT OF "1500921000000" MILISECOND
alert(format(new Date(1500921000000).getTime(), 'MM/dd/yyyy'))
try that then let me know the result, Thanks
链接地址: http://www.djcxy.com/p/8166.html上一篇: 来自控制器的javascript日期
下一篇: 如何将毫秒转换为日期