JS日期時間格式轉換

Wed Jan 09 2019 00:00:00 GMT+0800 (中國標準時間)

Thu Sep 26 2019 00:00:00 GMT+0800 (中國標準時間)

轉換成格式爲 :  20190109 00:00

轉換成格式爲 :  20190926 00:00

var start = new Date($scope.date[i].start); //Wed Jan 09 2019 00:00:00 GMT+0800 (中國標準時間)
var startDate = start.getFullYear() + '' + ((start.getMonth() + 1)<10 ? '0' + (start.getMonth() + 1):(start.getMonth() + 1)) + '' + (start.getDate()<10 ? '0' +start.getDate():start.getDate()) + ' ' + (start.getHours()<10 ? '0' +start.getHours():start.getHours()) + ':' + (start.getMinutes()<10 ? '0' +start.getHours():start.getHours());
var end = new Date($scope.date[i].end); //Thu Sep 26 2019 00:00:00 GMT+0800 (中國標準時間)
var endDate = end.getFullYear() + '' + ((end.getMonth() + 1)<10 ? '0' + (end.getMonth() + 1):(end.getMonth() + 1)) + '' + (end.getDate()<10 ? '0' + end.getDate():end.getDate()) + ' ' + (end.getHours()<10 ? '0' +end.getHours():end.getHours()) + ':' + (end.getMinutes()<10 ? '0' +end.getMinutes():end.getMinutes());
console.log(startDate); //20190109 00:00
console.log(endDate); //20190926 00:00

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章