将Days,Hours,Minutes和Seconds转换为整数

时间:2017-07-12 11:08:05

标签: php date date-arithmetic

我可以将int转换为天,小时,分钟和秒,但是反转它并转换回秒的计算是什么?

这是我第一次转换的内容:

<?php
$seconds = 12345;
$days = floor ($seconds / 60 / 60 / 24);
$hours = floor ($seconds / 60 / 60) % 24;
$minutes = floor ($seconds / 60) % 60;
$seconds = $seconds % 60;
?>

2 个答案:

答案 0 :(得分:1)

$total = ($days * 24 * 60 * 60) + ($hours * 60 * 60) + ($minutes * 60) + $seconds;

答案 1 :(得分:0)

试试这个

$total = ($days * 24 * 60 * 60) + ($hours * 60 * 60) + ($minutes * 60) + $seconds;