如何检测用户时区 [英] how to detect users timezone

查看:192
本文介绍了如何检测用户时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道我的用户目前的时区是基于他们的Ip或http标头。

i need to know what time zone is currently my users is in based on their Ip or http header.

这对我来说非常紧急。我有很多关于这个问题的答案,但我不能理解这些答案。
有人说使用 -new Date()。getTimezoneOffset()/ 60; 从这里)。这是什么意思?

This is very urgent to me. I got many answer regarding this issue, but i could not understood those answer. Some said use -new Date().getTimezoneOffset()/60;(from here) .But what does it mean ?

我在我的(index.php)的根目录中有一个 date_default_timezone_set(Asia / Calcutta); 页。所以为此我必须动态获得时区,并将其设置为亚洲/加尔各答

I have a date_default_timezone_set("Asia/Calcutta"); in the root of my (index.php)page. so for this i have to get the timezone dynamically and set it in place of Asia/Calcutta.

- 提前感谢

推荐答案

感谢您 Ashutosh 提出这个讨论,并感谢您百万个 Matt Johnson ,以便与我们分享您在时区上的知识。

Thank you Ashutosh for bringing up this discussion and Thanks a million to Matt Johnson for sharing your knowledge with us on time zone.

总结马特·约翰逊的答案的代码:

To summarize Matt Johnson's answer in terms of code:

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js">
</script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jstimezonedetect/1.0.4/jstz.min.js">
</script>
<script type="text/javascript">
  $(document).ready(function(){
    var tz = jstz.determine(); // Determines the time zone of the browser client
    var timezone = tz.name(); //'Asia/Kolhata' for Indian Time.
    $.post("url-to-function-that-handles-time-zone", {tz: timezone}, function(data) {
       //Preocess the timezone in the controller function and get
       //the confirmation value here. On success, refresh the page.
     });
  });
</script>

这篇关于如何检测用户时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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