1

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

Kaushik Ray
  • 555
  • 2
  • 8
  • 21

1 Answers1

0

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.

Community
  • 1
  • 1
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
  • Matt Thanks for the explanation, but what I need is all possible Time Zone values that I can get using Javascript. For eg if i do Date d = new Date();alert(d); It will give something like - Tue Dec 17 2013 14:07:42 GMT+0530 (India Standard Time). Can i get all possible values like (India Standard Time) that Javascript might return.? – Kaushik Ray Dec 17 '13 at 08:40
  • No. That isn't possible without one of the libraries I mentioned. The "India Standard Time" is not coming from JavaScript itself, but rather from the particular web browser (or other environment) that you are using. It will be very different depending on which browser you are using, and even then it is not necessarily useful. If you could elaborate on *why* you want to do that, perhaps I can offer an alternative suggestion. – Matt Johnson-Pint Dec 17 '13 at 15:53
  • basically I want to get user's current local time zone, which I will be using in Salesforce which is having its corresponding specific time zones. I want to map the javascript time zones to Salesforce time zones and use them accordingly in the salesforce code. I hope I was able to describe the functionality I want to do. – Kaushik Ray Dec 17 '13 at 16:52
  • Wow, this is certainly an [XY Problem](http://meta.stackexchange.com/a/66378/201534)... You should ask at a broader level, but in general it seems you are trying to to time zone detection, which you might want to use [jsTimeZoneDetect](https://bitbucket.org/pellepim/jstimezonedetect). I'm almost positive SalesForce uses [IANA time zones](http://www.iana.org/time-zones) (such as `America/Los_Angeles`). Time zone offsets will not help you here. – Matt Johnson-Pint Dec 17 '13 at 17:31