toISOString() bug
Categories
(developer.mozilla.org Graveyard :: General, defect)
Tracking
(Not tracked)
People
(Reporter: comanicibogdy, Assigned: sheppy)
References
()
Details
(Whiteboard: [specification][type:bug])
What did you do?
1. console.log(new Date(2019, 3, 12).toISOString())
2.
3.
What happened?
2019-04-11T21:00:00.000Z
What should have happened?
2019-04-12T00:00:00.000Z
Is there anything else we should know?
Its not print normally
Comment 1•7 years ago
|
||
The page https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date has this note:
Where
Dateis called as a constructor with more than one argument, the specified arguments represent local time. If UTC is desired, usenew Date(Date.UTC(...))with the same arguments.
So, Date(2019, 4, 12) creates a date at midnight in your local time (UTC+3, eastern Europe / middle east / east Africa), and toISOString() prints that date in Coordinated Universal Time (UTC).
If you want midnight UTC, then use:
console.log(new Date(Date.UTC(2019, 4, 12)).toISOString())
Sheppy, do you think page needs to be more explicit?
| Assignee | ||
Comment 2•7 years ago
|
||
I've updated the article to hopefully be clearer on these points, along with some others.
| Assignee | ||
Updated•7 years ago
|
Updated•6 years ago
|
Description
•