gpt4 book ai didi

php - 如何将日期转换为小时

转载 作者:可可西里 更新时间:2023-10-31 23:38:33 26 4
gpt4 key购买 nike

我有:

hours1 : 403440

date2 为:2016/01/10

我需要以小时为单位转换 date2 并找到两者之间的差异,它应该再次以小时为单位。

最佳答案

date 的第二个参数是以秒为单位的 unix 时间戳,因此您的小时数乘以 3600(每小时 3600 秒)。

$hours1 = 403440 * 3600;
$date1 = date("d-m-Y H:i:s", $hours1);
echo $date1;

输出:

09-01-2016 19:00:00

根据您的更新,您的代码应该是:

$date2 = strtotime('2016/01/10');//get date to seconds from 1970
$hours1 = 403440 * 3600; // convert from hours to seconds
echo ($date2 - $hours1)/3600;//subtract seconds then divide by 3600 to get how many hours difference is

输出:

5

关于php - 如何将日期转换为小时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33930956/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com