开发者

What is the best way of getting the timezone from the city, country that user selects?

开发者 https://www.devze.com 2023-03-25 07:45 出处:网络
I looked into javascript, and thought about using the client\'s clock, but it doesn\'t seem very reliable since the client\'s clock is out of my control.

I looked into javascript, and thought about using the client's clock, but it doesn't seem very reliable since the client's clock is out of my control.

I looked around for web serv开发者_开发知识库ices but wasn't lucky.

Basically what I want is to display a specific time (e.g. 9:00:00 GMT +4) in the user's timezone, based on location provided (city, country).

Thanks


I think this JavaScript tool jsTimezoneDetect is what you need. It is very easy to use and it can detect a pretty big range of timezones. Besides, if you want to detect the timezone from the country and city that the user selected, I think you would need to store the whole Olson timezone database and make Ajax call to get what you need.


If you're limiting the list of cities to the cities supported by PHP it's pretty easy, you can then use the DateTimeZone class.

If you're allowing the user to choose any old city and want to work out the timezone from that then I'm pretty sure there isn't a maintained mapping file.

You could use a webservice to look up the latitude and longitude of a city and then plug that latitude &longitude into Ask Geo or a similar webservice. You'd need to ask the country too there's a Cairo in the USA and in Egypt.

0

精彩评论

暂无评论...
验证码 换一张
取 消