如何在 PHP 中获取当前浏览器时区? [英] How to get current Browser TimeZone in PHP?

查看:65
本文介绍了如何在 PHP 中获取当前浏览器时区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试这个代码

<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 文件中

But i want in php file

推荐答案

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

hi i solved this question answer :

<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 Code Calaculate diff between two Time Zone:

<?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);
    }
 ?>

这篇关于如何在 PHP 中获取当前浏览器时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆