PHP时间加上小时错误

时间:2015-12-05 20:03:30

标签: php

我尝试在服务器时间增加几个小时,但是当我尝试教程时,我遇到了一个令人困惑的时间。

代码:

$timestamp = time();
$datum = date("d.m.Y",$timestamp);
$now = date("H:i",$timestamp);
//Actual Week Day
$dw = date( "w", $timestamp);
echo $datum," - ",$now," oclock "," Weekday ",$dw; 
//Add hours to server time
$timeadd = date("H:i", strtotime("+ 8 hours",$now));
echo " Time add = ", $timeadd;

这是输出:

  

05.12.2015 - 20:55 oclock Weekday 6 Time add = 09:00

为什么Time的输出始终是09:00?

1 个答案:

答案 0 :(得分:2)

这一行

$timeadd = date("H:i", strtotime("+ 8 hours",$now));

需要:

$timeadd = date("H:i", strtotime("+ 8 hours",$timestamp));

我认为你将strtotime与你传入的内容混淆在一起,它只需要你在时间开始时得到的原始时间戳()。