dpxkkhu1812 2019-05-04 13:27
浏览 37
已采纳

为什么+3小时的另一个输出为+3小时?

I am writing a small Time calculation. It should always add 3h to a given time.

But if i do "+3 h" in the method strtotime() in php it will output another value. So I wonder why "+3 hours" will work. Can somebody explain me why?

My php version is: 7.0.33-0ubuntu0.16.04.4

$date = "2019-05-04 15:00"; //format is Y-m-d H:i
$out = date("Y-m-d H:i", strtotime("+3 h", strtotime($date)));
echo $out; //out = 2019-05-04 14:00

$date = "2019-05-04 15:00"; //format is Y-m-d H:i
$out = date("Y-m-d H:i", strtotime("+3 hours", strtotime($date)));
echo $out; //out = 2019-05-04 18:00

This is a test example code from me. And $date is a different value every 15min.

PS: this is my first question on stackoverflow - Hello World :D

  • 写回答

1条回答 默认 最新

  • donglu0494 2019-05-04 13:51
    关注

    strtotime - Parse about any English textual datetime description into a Unix timestamp

    You need to use hour OR hours. Similar for days you can use day or days.

    $date = "2019-05-04 15:00"; //format is Y-m-d H:i
    $out = date("Y-m-d H:i", strtotime("+3 h", strtotime($date)));
    echo $out; //out = 2019-05-04 12:00
    

    The output is showing 2019-05-04 12:00 not 2019-05-04 14:00.

    It seems when you put the wrong format; ike +3 h, it's just subtracting that from the original time

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大