开发者

how to show time and date according to user client (in lamp)

how in lamp (LINUX ,APACHE ,MYSQL ,PHP) environme开发者_如何学Gont , can i show date and time in web page according to the user time zone ?

THANKS


Use JavaScript to determine the timezone of the user:

new Date().gettimezoneOffset()


On the PHP side this code works fine...

  echo <<<EOE
   <script type="text/javascript">
     if (navigator.cookieEnabled)
       document.cookie = "tzo="+ (- new Date().getTimezoneOffset());
   </script>
EOE;
  if (!isset($_COOKIE['tzo'])) {
    echo <<<EOE
      <script type="text/javascript">
        if (navigator.cookieEnabled) document.reload();
        else alert("Cookies must be enabled!");
      </script>
EOE;
    die();
  }
  $ts = new DateTime('now', new DateTimeZone('GMT'));
  $ts->add(DateInterval::createFromDateString($_COOKIE['tzo'].' minutes'));
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜