D
D
Drovosek012022-02-18 21:40:14
Angular
Drovosek01, 2022-02-18 21:40:14

Why does the date in Angular get 3 hours late?

I am writing tests in Angular 13 using Jest.

At the very beginning, in describe('', () => {}) I create a field for the date Next, after .compileComponents(), I write the date in the defaultDate field and then immediately display it in the console
let defaultDate: Date;

defaultDate = new Date(2021, 1, 1, 0, 0, 0);
console.log('default date is', defaultDate);


I run a test that checks that the component was just created and the date is displayed in the terminal 2021-01-31T21:00:00.000Z.
If I display the same date in the devTools console in GoogleChrome, then the value that I set in the date is displayed there -
Mon Feb 01 2021 00:00:00 GMT+0300 (Москва, стандартное время)


I googled and found 2 links on this topic:
https://ru.stackoverflow.com/questions/770059/%D0%...
https://stackoverflow.com/questions/55005125/date-...

Alas, I'm all I still didn’t understand why 3 hours were taken away from the date where I specifically set all the parameters.
Please can someone explain in layman's terms why Angular (or Jest) changes the date as opposed to the DevTools console.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Roo, 2022-02-18
@xez

2021-01-31T21:00:00.000ZZ is Greenwich Mean Time.
Mon Feb 01 2021 00:00:00 GMT+0300GMT+3 is in Moscow.
The time is the same, but the output is in different formats.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question