getting time zone when entering state and country (time zone to use in ics file)

后端 未结 3 1684
南笙
南笙 2021-01-22 00:31

Getting time zone when giving state and country in text box

is there any way to get the time zone of that place with this two values?

the input

相关标签:
3条回答
  • 2021-01-22 01:22

    This is impossible, for the simple reason that quite a few states span more than one timezone. See Wikipedia's list. Outside the US it can get even more complicated; I believe there are some cities that span multiple timezones.

    You could cobble together guesses per state (e.g. by using that list), but if this is for figuring out the user's timezone, you'll probably have better luck just comparing the client clock with the server's UTC time and estimating based on country.

    edit: Note that there's no way to ask the browser for the current timezone, either, and you can't guess reliably based on the current time, because there are many timezones where it's the same time right now but where DST is different. Your best bet is to find all the possible current timezones, estimate based on the user's location (which you also have to guess!), and just ask as a last resort.

    0 讨论(0)
  • 2021-01-22 01:24

    No, there is no pre-defined methods exists.

    For this you need some external web services. If you're interested you can create your own API using the information provided here in wikipedia

    Updates: Based on your comments "get local time zone of the current browser

    var date = new Date(); 
    

    returns 12:38:05 GMT+0530 (India Standard Time)

    To pick the time within the bracket use

    date.toTimeString().match(/\(([^)]+)\)/)[1];
    

    returns India Standard Time

    Check this JSFiddle

    But this is not you expected, however you should try Auto detect a time zone with JavaScript and for updated version try this jsTimezoneDetect

    0 讨论(0)
  • 2021-01-22 01:24

    GeoNames provides a data dump that you can use:

    http://download.geonames.org/export/dump/

    This is per skylarsutton's response in the following previous post with a similar question (but not specific to js or query)...

    I need a mapping list of cities to timezones- best way to get it?

    0 讨论(0)
提交回复
热议问题