How to detect user's timezone?

后端 未结 6 1112
独厮守ぢ
独厮守ぢ 2020-11-22 13:00

I need to know what time zone is currently my users are in based on their IP or http header.

I got many answer regarding this issue, but i could not understood thos

6条回答
  •  天涯浪人
    2020-11-22 14:00

    This works fine...

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

提交回复
热议问题