Local / UTC date-time in Date

There are time and time strings that have been combined with date and time values:

const localDatetime = `2017-01-01T12:00`;
const utcDatetime = `2017-01-01T12:00`;

and must be converted to an object Date.

In Firefox, this is accepted as local time:

new Date('2017-06-12T12:00').toISOString() === '2017-06-12T08:00:00.000Z'

And in Chrome, this is accepted as UTC time:

new Date('2017-06-12T12:00').toISOString() === '2017-06-12T12:00:00.000Z'

It looks incompatible, to say the least.

What is the explanation? Which of these browsers is right and why?

What is a cross-browser solution for correctly performing this conversion for both local and UTC strings?

+4
source share

Source: https://habr.com/ru/post/1679062/


All Articles