var td = (new Date('2017-05-16 13:45')); console.log(td); //вывод: 2017-05-16T08:45:00.000Z console.log(td.getHours()); //вывод: 13 Tell me why such a conclusion? he prints time by GMT. I am in the UTC + 5 zone
var td = (new Date('2017-05-16 13:45')); console.log(td); //вывод: 2017-05-16T08:45:00.000Z console.log(td.getHours()); //вывод: 13 Tell me why such a conclusion? he prints time by GMT. I am in the UTC + 5 zone
To display the date, it is better to use toLocaleString , with options:
var td = new Date('2017-05-16 13:45'); console.log(td) console.log(td.toLocaleString()) console.log(td.toLocaleString("ru", {timeZone: 'UTC'})) console.log(td.toLocaleString("ru", {timeZone: 'Europe/Moscow'})) console.log(td.toLocaleString("ru", {timeZone: 'Europe/Moscow', era: 'long'})) A list of the remaining options can be found here.
Source: https://ru.stackoverflow.com/questions/786067/
All Articles