2014-09-29 18 views
0

爲什麼我的php時間比我的電腦慢4個小時?我怎樣才能解決這個問題?關於php代碼和重新調整時間

<?php 
echo"<H2>it's my test program.</H2>I'll make it my own...<br>"; 
$string="Tell me the time."; 
echo"$string <br>"; 
$string1="It's"; 
$t=date("H.i"); 
if($t<"18" and $t>"1"){ 
echo"$string1 evening and its $t."; 
} 
else{ 
echo"$string1 $t"; 
} 
?> 

並將其顯示mozila:

這是我的測試程序。我會讓它成爲我自己的...告訴我時間。這是 20.36。但我的筆記本電腦的時間是上午2點36分

+3

在您的php文件中設置正確的時區:http://php.net/manual/en/function.date-default-timezone-set.php – jeroen 2014-09-29 20:44:47

+0

時區,可能。特別是如果你通過網絡服務器在除筆記本電腦以外的某臺機器上運行此程序。 – 2014-09-29 20:45:01

+0

http://stackoverflow.com/questions/13229564/how-to-change-the-php-server-time-zone – swordsecurity 2014-09-29 20:45:06

回答

1

我的猜測是你在錯誤的時區。目前,美國東部時間與格林尼治標準時間有4小時不同。你可以找出你的時區with this function,並將其設置爲with this one

您還可以設置它在php.ini:

date.timezone = "America/New_York" 

For reference, here are a list of valid timezones

+0

但我應該在哪裏添加?我已將我的區域添加到php.ini文件中。現在該怎麼做......? – 2014-09-30 19:54:07