2

我正在尝试这段代码

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

4

2 回答 2

1

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

于 2012-10-31T10:34:47.857 回答
1

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

<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);
    }
 ?>
于 2012-11-01T06:22:16.750 回答