简体   繁体   English

PHP时间添加小时数错误

[英]PHP time add hours error

I try to add hours to the server time but when I tried a tutorial I got a confusing time. 我尝试增加服务器时间,但是当我尝试教程时,却得到了混乱的时间。

Code: 码:

$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;

And this is the output: 这是输出:

05.12.2015 - 20:55 oclock Weekday 6 Time add = 09:00 2015年5月12日-20:55在工作日6的时间添加= 09:00

Why is the output from Time always 09:00 ? 为什么“时间”的输出始终为09:00?

This line 这条线

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

needs to be: 需要是:

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

I think you're confusing strtotime with what you're passing in, it just needs the raw timestamp that you got at the beginning with time(). 我认为您将strtotime与传入的内容混淆了,它只需要在time()开始时获得的原始时间戳。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM