Closed Bug 1543992 Opened 7 years ago Closed 7 years ago

toISOString() bug

Categories

(developer.mozilla.org Graveyard :: General, defect)

All
Other
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

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

The page https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date has this note:

Where Date is called as a constructor with more than one argument, the specified arguments represent local time. If UTC is desired, use new 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?

Flags: needinfo?(eshepherd)

I've updated the article to hopefully be clearer on these points, along with some others.

Assignee: nobody → eshepherd
Flags: needinfo?(eshepherd)
Status: UNCONFIRMED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Product: developer.mozilla.org → developer.mozilla.org Graveyard
You need to log in before you can comment on or make changes to this bug.