1、將中國標準時間格式化為(2017-06-06 15:05:04)
function formatDateTime(theDate) {
var _hour = theDate.getHours();
var _minute = theDate.getMinutes();
var _second = theDate.getSeconds();
var _year = theDate.getFullYear()
var _month = theDate.getMonth();
var _date = theDate.getDate();
if(_hour<10){_hour="0"+_hour ;}
if(_minute<10){_minute="0"+_minute; ?}
if(_second<10){_second="0"+_second ?}
_month =?_month + 1;
if(_month < 10){_month = "0" + _month;}
if(_date<10){_date="0"+_date ?}
return ?_year + "-" + _month + "-" + _date + " " + _hour + ":" + _minute + ":" + _second ;
}
var time = new Date();
var formatTime =?formatDateTime(time?);
返回結果:
Tue Jun 06 2017 15:31:09 GMT+0800 (中國標準時間)
2017-06-06 15:31:09
2、把格式化時間轉換為毫秒數
var formatTimeS =?new Date('2017-06-06 15:31:09').getTime();
返回結果:1496734269900
3、把毫秒數轉換為標準時間
var formatTimeS =?new Date(1496734269900);
返回結果:
Tue Jun 06 2017 15:31:09 GMT+0800 (中國標準時間)
---------------------
作者:木雷雙雄7
來源:CSDN
原文:https://blog.csdn.net/wlangmood/article/details/72879607
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!