I just found that if I use new Date('2015-1-1')
, the time is no timezone effect, but If I use new Date('2015-01-01')
the time has timezone effect in Node.js.
I output 4 Date()
:
console.log(new Date('2015-1-1'));
console.log(new Date('2015-01-1'));
console.log(new Date('2015-1-01'));
console.log(new Date('2015-01-01'));
the output is
Thu Jan 01 2015 00:00:00 GMT+0800 (CST)
Thu Jan 01 2015 00:00:00 GMT+0800 (CST)
Thu Jan 01 2015 00:00:00 GMT+0800 (CST)
Thu Jan 01 2015 08:00:00 GMT+0800 (CST)
you can see the last time is 08:00:00
because I'm in +8 timezone.
I think the output depends on the digit of the month or date number. When it's 10, 11 or 12 the output is always 08:00:00
I'm wondering why and if there is a better way to handle this except manually check the bit of month and date number?