在javascript中获取用户时区和地理位置
我正在尝试获取用户的时区。我可以做到这一点,但如何识别具有相同时区的两个地理区域,例如亚利桑那州时区与山地时间(美国和加拿大)相同的UTC-07:00,当我从用户那里获取时区时,我只得到-07: 00,但我不知道用户是否位于亚利桑那时区或山地时区。关于如何识别这一点有任何提示吗?
我需要这样的 Java 代码:
TimeZone tz = Calendar.getInstance().getTimeZone();
System.out.println("TimeZone: "+tz.getDisplayName());
System.out.println("ID: "+tz.getID());
但对于 javascript。
I am trying to get a user's timezone. I can do this, but how can I identify two geographic zones with same timezone, for example Arizona timezone is UTC-07:00 same that Mountain time (US & Canada) and when I get timezone from user I only get -07:00, but I don´t know if user is in Arizona timezone or Mountain time timezone. Any hint about how to identify this?
I need something like this code in Java:
TimeZone tz = Calendar.getInstance().getTimeZone();
System.out.println("TimeZone: "+tz.getDisplayName());
System.out.println("ID: "+tz.getID());
but for javascript.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:我想我找到了更简单的答案来解决您的问题。查看这篇文章底部的代码。
嗯,亚利桑那州的时区与山区时区相同。因此,如果某人位于亚利桑那州时区,那么他们也位于山区时区,反之亦然。这两个时区是相同的。但是,如果您只是查找用户的地理位置,请尝试使用此相关api 结合一些 代码,看起来像这个。
基本上,此代码的作用是:
您的用户计算机访问 geoplugin.net,然后返回与用户 IP 地址相关的信息。
您解析返回的数据并对其执行任何您想要的操作。
希望这有帮助!
Edit: I think I found a simpler answer to your problem. Look at the code at the bottom of this post.
Well, Arizona's time zone is the same as Mountain time zone. Therefore if someone is in Arizona time zone, they are also in Mountain time zone, and vice-versa. The two timezones are one and the same.If you are just looking for your user's geographical location however, try using this relevant api in conjunction with some code that looks like this.
Basically what is done in this code is:
Your user's machine accesses geoplugin.net, which then returns info relating to the user's IP address.
You parse the returned data and do whatever you want with it.
Hope this helps!