How to get the current time/timezone of the user visiting my website?

拈花ヽ惹草 提交于 2019-12-24 20:03:46

问题


I am working on an application which utilizes PHP (Zend Framework) and JavaScript (jQuery).

I'm trying to get the current time of the user visiting the site. Is this possible? How can this be done?


回答1:


adapted from: http://kennyshu.blogspot.com/2009/05/javascript-get-clients-timezone.html

  <script type="text/javascript"> 
  var gmtOffset
  function timezone()  
  {  
    var localTime = new Date();  
    //this one will give you the GMT offset  
    gmtOffset = localTime.getTimezoneOffset()/60 * (-1);  
  }  
  </script>

then post back the variable gmtOffset to your application.




回答2:


You can get their ip and look it up via a web service or a database, of which I'm sure someone will reply with, or has already replied with in the duplicate question. :-)



来源:https://stackoverflow.com/questions/2419808/how-to-get-the-current-time-timezone-of-the-user-visiting-my-website

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!