这很奇怪,但似乎是新的日期(params),当以正确的年,月,日,小时,分钟,秒,毫秒格式传递时,它提前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上运行,并且创建的日志位于dateTime之前,这很奇怪。除了这个月,其他一切都没问题。 02是2月对吗?我很困惑。谢谢你的帮助!