So the problem was that there were missed Z
letter.
How it works?
There are special standartized date string format, its ISO format.
There are no timezones. There are only one timezone and this is Z (zulu, Grinvich).
So.. in any programming language, when we tranform any date to ISO string format, then transofrmer automaticaly do next things
- It transofrm our date to Grinwich timezone
- Transform Grinviched date into string
And. When we call new Date('dateString')
constructor, then it began to read date and if it (browser) doesnt know something, then it (browser) just set something by default.
In my case, I had sent to the browser string like this "2021-03-05T18:23:42"
Here are year, month, day, hour, minute. But there are not timezone. So when browser read this string, he set current user's timezone by default.
But. When I add 'Z' (I mean string became "2021-03-05T18:23:42Z"
, then I said to browser: "hey, browser, here is 2021 03 05 18:23 by Grinvich". And when I ask browser
const date = new Date("2021-03-05T18:23:42Z") // pay attention at Z in the end
, browser make 2 things
- Read this string and create Date object knowing that this moment in life (time) is wroted by Grinvich
- Transform this time to time in current user's timezone
I'm happy
Hope your are too :)