0

On my workstation using several browsers, JavaScript's new Date().toString() method returns a string such as:

Thu Aug 15 2019 17:34:40 GMT-0500 (Central Daylight Time)

I'm interested in how it knows about "Central Daylight Time"?

I know how to get the offset (e.g. -300) using getTimeZoneOffset(), but I don't see any documented approach to get the named time zone.

Is parsing the output of toString() really the best approach?

matthewsteele
  • 1,797
  • 1
  • 15
  • 31

1 Answers1

-1

If you check the docs here, Javascript should return the offset of the local time zone from UTC measured in milliseconds at local time, When the result is subtracted from the local time it should yield the corresponding UTC. Although there is no mention of how the low-level operation is made to get the current pc time.

Dan Starns
  • 3,765
  • 1
  • 10
  • 28
  • that's exactly what the OP does NOT want. a timezone offset in units of milliseconds is no more use for identifying the timezone than a timezone offset in minutes – Jaromanda X Aug 15 '19 at 23:05
  • the docs also mention that implementations are advised to use [iana](https://www.iana.org/time-zones) to compare the offset to get the timezone. – Dan Starns Aug 15 '19 at 23:07
  • `compare the offset to get the timezone` ... again, a time offset can not help you find a timezone - for a start, there's at least two hemisphere's, north and south, where things like summer time is different – Jaromanda X Aug 15 '19 at 23:13