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.).
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料