javascript - getting time zone when entering state and country (time zone to use in ics file) - Stack Overflow

Getting time zone when giving state and country in text boxis there any way to get the time zone of tha

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' ;
var country = 'United States';

result should be

America/New_York

OR

get local time zone of the current browser?

I need this 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' ;
var country = 'United States';

result should be

America/New_York

OR

get local time zone of the current browser?

I need this time zone to use in ics file.

Share Improve this question edited Nov 5, 2013 at 7:00 Reshma asked Nov 5, 2013 at 6:43 ReshmaReshma 5023 gold badges9 silver badges23 bronze badges 3
  • Check this:stackoverflow./questions/6934757/… – Joke_Sense10 Commented Nov 5, 2013 at 6:49
  • ok can i get a little help to get local time zone of the current browser? – Reshma Commented Nov 5, 2013 at 6:55
  • To get local time zone of current browser:stackoverflow./questions/6939685/… – Joke_Sense10 Commented Nov 5, 2013 at 7:07
Add a ment  | 

3 Answers 3

Reset to default 3

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 plicated; 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 paring 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.

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 ments "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

GeoNames provides a data dump that you can use:

http://download.geonames/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?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744720987a4589907.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信