输入州和国家/地区时获取时区(在ics文件中使用的时区) [英] getting time zone when entering state and country (time zone to use in ics file)

查看:351
本文介绍了输入州和国家/地区时获取时区(在ics文件中使用的时区)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在文本框中输入州和国家/地区时获取时区

是否有任何方法可以使用这两个值来获取该地点的时区?

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

输入就像

var state = 'New York' ;
var country = 'United States';

结果应为

美国/纽约

OR

获取当前浏览器的本地时区?

get local time zone of the current browser?

我需要这个时区才能在ics文件中使用.

推荐答案

这是不可能的,原因很简单,许多州跨越多个时区.请参见维基百科的列表.在美国以外,情况可能会变得更加复杂.我相信有些城市跨越多个时区.

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.

您可以将每个状态的猜测拼凑在一起(例如,通过使用该列表),但是如果这是为了弄清 user 的时区,那么只需比较客户端时钟,您可能会遇到更好的运气服务器的UTC时间并根据国家/地区进行估算.

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:请注意,也没有办法向浏览器询问当前时区,并且您也无法基于当前时间进行可靠猜测,因为现在有许多时区是同一时间 ,但DST不同.最好的选择是找到所有可能当前时区,根据用户所在的位置(您也必须猜测!)进行估算,最后选择询问.

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.

这篇关于输入州和国家/地区时获取时区(在ics文件中使用的时区)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆