【问题标题】:How to get current Browser TimeZone in PHP?如何在 PHP 中获取当前浏览器时区?
【发布时间】:2012-10-31 10:31:04
【问题描述】:

我正在尝试这段代码

<script> 
var rightNow = new Date();
var jan1 = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0, 0);
var temp = jan1.toGMTString();
//document.hari.maliya.value=temp;
//alert(temp);
document.write(temp);
 <script>  

但我想在 php 文件中

【问题讨论】:

    标签: time timezone


    【解决方案1】:

    您必须将此值作为 cookie、http 参数或使用 ajax 调用传递给您的 php 脚本。

    【讨论】:

      【解决方案2】:

      嗨,我解决了这个问题的答案:

      <script> 
      $(document).ready(function() {
          var rightNow = new Date();
          //alert(temp);
           document.harimaliya.timezone.value=rightNow;
      });
      </script>
      

      和html代码是:

          <form name="harimaliya" id="harimaliya" action=""  method="post">
              time zone :<input type="text" name="timezone" id="timezone" value='' size="50"/> 
              <input type="submit" value="Test Diffrent time Zone" name="timezonetest" id="timezonetest">
          </form>
      

      PHP 代码计算两个时区之间的差异:

      <?php
          if(isset($_POST['timezonetest']))
            {
          echo "User Time Zone -:"." ".$usertimezone  = "(GMT-12:00)-International Date Line West";
          echo "<br>";
          $usertimezone = substr ($usertimezone, 1,9);
          echo $usertimezone= str_replace(':',"",$usertimezone);
          echo "<br>";
          echo date(strtotime("$usertimezone"));
          echo "<br>";
          echo "System Time Zone -:"." ".$systemtimezone= $_POST['timezone'];
          $systemtimezone = strstr($systemtimezone, 'G');
          echo "<br>";
          echo $systemtimezone = substr ($systemtimezone, 0,8);
          echo "<br>";
          echo date(strtotime("$systemtimezone"));
          echo "<br>";
          echo $diff=date(strtotime("$usertimezone"))-date(strtotime("$systemtimezone"));
          echo "<br>";
      
          echo $diff=($diff/60)." "."minits";
          echo "<br>";
          echo $diff=($diff/60);
          }
       ?>
      

      【讨论】:

        猜你喜欢
        • 2015-08-26
        • 2014-04-13
        • 2014-06-26
        • 1970-01-01
        • 2014-04-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-03-25
        相关资源
        最近更新 更多