Reputation: 2054
I am trying to convert a date, but it shows differently on a set date between time zones.
new Date(1404100800000)
Mon Jun 30 2014 00:00:00 GMT-0400 (Eastern Daylight Time)
new Date(1404100800000)
Sun Jun 29 2014 21:00:00 GMT-0700 (Pacific Daylight Time)
Why does it do that? I must be not understanding something about dates.
Upvotes: 0
Views: 54
Reputation: 543
This is expected. The timestamp number is measuring time independent of timezone. When converted to human readable format, it will change based on the timezone of the system. This is exactly as you'd expect, so that an event that occured at 6pm in New York will not also be an event at 6pm in San Fransisco ... but they will have the same timestamp.
From ECMA standard:
Time is measured in ECMAScript in milliseconds since 01 January, 1970 UTC. In time values leap seconds are ignored. It is assumed that there are exactly 86,400,000 milliseconds per day.
http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.1.1
Conversion to string is locale dependent:
This function returns a String value. The contents of the String are implementation-dependent, but are intended to represent the Date in the current time zone in a convenient, human-readable form.
http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.5.2
Upvotes: 1