-3
這是非常奇怪的,但似乎新的日期(params),當以正確的格式傳遞年,月,日,小時,分鐘,秒,毫秒,超過1個月。DateTime新的日期(params)在JavaScript是更快的1個月
看看下面的實現:
// The format below needs to be changed according to req.param('dateTime')
// dateTime format is as follows: "dd/MM/yyyy HH:mm:ss"
var dateTime = report['dateTime'];
console.log('dateTime: '+dateTime);
var dateTimeSplit = dateTime.split(' ');
var dateSplit = dateTimeSplit[0].split('/');
var timeSplit = dateTimeSplit[1].split(':');
var day = parseInt(dateSplit[0]);
var month = parseInt(dateSplit[1]);
var year = parseInt(dateSplit[2]);
var hour = parseInt(timeSplit[0]);
var minute = parseInt(timeSplit[1]);
var second = parseInt(timeSplit[2]);
var createdAt = new Date(year, month, day, hour, minute, second, 0);
console.log('createdAt: '+createdAt);
而且從日誌的結果是:
Feb 09 04:13:46 sails-wusrs app/web.1: createdAt: Mon Mar 09 2015 12:02:24 GMT+0000 (UTC)
Feb 09 04:13:46 sails-wusrs app/web.1: dateTime: 09/02/2015 12:02:24
該服務器在Heroku上運行,並且它的怪異的是createdAt的日誌中dateTime的前面。其他一切都是正常的,除了這個月。 02是2月吧?我很困惑。謝謝你的幫助!
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date – 2015-02-09 12:45:51
感謝@salman我開始得到它了。 (: – holyxiaoxin 2015-02-09 12:48:14
可能重複[JavaScript日期對象的月份索引以0開頭!](http://stackoverflow.com/questions/1208519/javascript-date-objects-month-index-begins-with-0) – 2015-02-09 13:06:39