简体   繁体   中英

Get only Timezone using Javascript

I am trying to get all possible time zone values that we can have using Javascript.

I used mulitple code statements like

d.getTimeZoneOffset()

and then normal new Date

but they give me corresponding to current local time. Is there any provision to get all possible time zone values that we get in Javascript.?

Thanks

getTimeZoneOffset gives you exactly that - the offset for the date value you provide, in the time zone of the machine that the code is running on. A "time zone" and a "time zone offset" are two different things. Please read the timezone tag wiki , especially the section titled "Time Zone != Offset".

The Date object can only represent (natively) the one time zone that is the local machine's time zone, and it has some functions for working with UTC. But other than that, it cannot express other time zones. For that, you need a library. See this question and its answer for details.

So to summarize, the question is nonsensical. JavaScript can't do what you're asking. Even if it could, the API allows for any numeric value to come back from getTimeZoneOffset , so the range of possible results is the same as the range of valid numbers in JavaScript. Although in practice it will fall somewhere between -840 and 720.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM