Skip to content Skip to sidebar Skip to footer

Getting Time Zone When Entering State And Country (time Zone To Use In Ics File)

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 will be like var state = 'New York'

Solution 1:

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.

Solution 2:

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 = newDate(); 

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

Solution 3:

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?

Post a Comment for "Getting Time Zone When Entering State And Country (time Zone To Use In Ics File)"