[英]Php Subtract Date Time
我在减去php中的日期时遇到问题。
这是我的代码。
$fulldate_hour_start = "2013-12-01 01:00:00";
$fulldate_hour_end = "2013-12-02 08:01:00";
$Result= number_format((((strtotime($fulldate_hour_end) - strtotime($fulldate_hour_start)) / 60) / 60 ),2);
echo $Result;
输出为31.02
应该只有31.01
我不知道我的代码出了什么问题或错了。谢谢您的帮助。
$fulldate_hour_start = "2013-12-01 01:00:00";
$fulldate_hour_end = "2013-12-02 08:01:00";
$difference = strtotime( $fulldate_hour_end .' UTC' ) - strtotime( $fulldate_hour_start .' UTC');
$Result = floor( $difference / 3600 ) .':' .gmdate( 'i', $difference );
echo $Result;
结果
31:01
您要计算的时间段是31.01666重复小时,该数字number_format()
舍入为31.02小时,因此,如果需要小时和小时分数,结果是正确的。 如果您需要小时和分钟,则需要更改计算以考虑每小时60分钟。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.