开发者

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

开发者 https://www.devze.com 2022-12-22 18:11 出处:网络
I am working on an application which utilizes PHP (Z开发者_StackOverflow社区end Framework) and JavaScript (jQuery).

I am working on an application which utilizes PHP (Z开发者_StackOverflow社区end 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?


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.


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. :-)

0

精彩评论

暂无评论...
验证码 换一张
取 消