我需要根据用户的 IP 或 http 标头了解用户当前所在的时区。
关于这个问题我得到了很多答案,但我无法理解这些答案。有的说用-new Date().getTimezoneOffset()/60
(从这里 https://stackoverflow.com/questions/13/determining-a-web-users-time-zone/1809974#1809974)。但是这是什么意思?
我有一个date_default_timezone_set("Asia/Calcutta");
在我的(index.php)页面的根目录中。因此,为此我必须动态获取时区并将其设置为Asia/Calcutta
.
用代码总结 Matt Johnson 的答案:
<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(); //For e.g.:"Asia/Kolkata" for the 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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)