I'm trying to parse fully specified date ISO string and then print the corresponding date object. My laptop is in Europe/Berlin
timezone (i.e UTC+02
at summer time). However when I explicitly set TZ=UTC+02
env variable for the node process, the script below produces unexpected results:
// test.js
const t = '2018-07-03T10:00:00.000+02:00';
console.log(t, new Date(t), new Date(t).toLocaleString());
$ TZ='UTC+02' node test.js
> 2018-07-03T10:00:00.000+02:00 2018-07-03T08:00:00.000Z 2018-7-3 06:00:00 // 6 AM!!!
Then I checked for the timezone offset (which must be opposite to UTC offset in accordance with the spec) and it gives me positive +02:00
value for TZ=Europe/Berlin
timezone and negative for the TZ=UTC+02
.
const x = new Date();
const offset= -x.getTimezoneOffset();
console.log((offset>=0?"+":"")+parseInt(offset/60)+":"+offset%60);
How can one explain such behaviour?
$ node --version # on OS X high sierra 10.13.4
> v8.7.0