JavaScript timezone information how to get America/Los_Angeles (or equivalent) -


im wondering there built in function in javascript has timezone information such

america/los_angeles (or equivalent) can determined on whatever factor need factored on?

similar http://momentjs.com/timezone/ on home page? or there list of these zones can attempt build own library off of? gather http://momentjs.com/timezone/ takes vaule america/los_angeles example determine offset, can't find mention of how opposite.

time zone detection in javascript imperfect. can local time zone offset particular date , time using gettimezoneoffset on instance of date object, that's not quite same full iana time zone america/los_angeles.

there options though:

  • the latest versions of chrome , opera support iana time zones in implementation of ecmascript internationalization api. in particular browsers, can this:

    intl.datetimeformat().resolvedoptions().timezone 

    the result string containing iana time zone of local computer. however, new, , it not yet implemented in browsers.

    also, understand make work on windows, chrome has rely on icu4c translate local computer's windows time zone id iana time zone id, using unicode cldr supplemental mappings.

    so, consider long-term resolution. it's not ready yet.

  • in meantime, can use jstimezonedetect library make educated guess @ time zone. works interrogating gettimezoneoffset @ several different points , using results choose appropriate time zone.

    moment.js has functionality now, in moment-timezone extension, moment.tz.guess(). has more robust implementation jstimezonedetect.

    it is, however, guess. work in many cases, not of them. additionally, has periodically updated counteract fact javascript implementations aware of current daylight saving time rule local time zone. more details on here.

ultimately, should ask user time zone. provide setting can change. can use 1 of above options choose default setting, don't make impossible deviate in app.

there's entirely different approach of not relying on time zone setting of user's computer @ all. instead, if can gather latitude , longitude coordinates, can resolve time zone using one of these methods. works best on mobile devices.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -