0

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
Ivan Velichko
  • 6,348
  • 6
  • 44
  • 90
  • Hey I've found this https://stackoverflow.com/questions/439630/how-do-you-create-a-javascript-date-object-with-a-set-timezone-without-using-a-s – t3__rry Jul 04 '18 at 12:40
  • @t3__rry it doesn't explain the difference of offsets for `Europe/Berlin` and `UTC+02`. – Ivan Velichko Jul 04 '18 at 12:42

0 Answers0