doujiang2641 2013-01-05 13:03
浏览 80
已采纳

javascript getTimezoneOffset()函数是否可靠返回准确的UTC偏移量?

To get UTC offset in php I could use date("Z") but as I think this will return the UTC offset relative to timezone of the server not relative to timezome of the user's computer, which I want to get. And when I searched I found that getting UTC offset relative to timezone of the user's computer can be done through the javascript getTimezoneOffset() function which returns the time difference between UTC time and local time, in minutes. And I have successfully used this javascript function in my php script. Now my question is: Is the javascritp getTimezoneOffset() function is always (or in most cases) reliable to return the accurate UTC offset relative to the user's computer?

  • 写回答

1条回答 默认 最新

  • dongyimo1293 2013-01-05 13:06
    关注

    This will depend on the user's date/time settings. It will give you the offset based on what the browser sees the timezone is set on the user's computer.

    But note that when you are using javascript, it is running on the client-side, i.e. on the browser, and not on the server-side. So you cannot use it in PHP, unless:

    • You store it in a cookie (via javascript) the first time a user visits your website.
    • You make an AJAX call to store a PHP code to store it in the session.
    • If you want to display a time on the user's computer, you send the time difference between the date you want to show and now(), and then you add that to the user's getTime() or you display the difference (i.e. 7 hours ago, 2 minutes ago, etc.).
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?
  • ¥15 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计