function secondsToTime($inputSeconds) {
$secondsInAMinute = 60;
$secondsInAnHour = 60 * $secondsInAMinute;
$secondsInADay = 24 * $secondsInAnHour;
$days = floor($inputSeconds / $secondsInADay);
$hourSeconds = $inputSeconds % $secondsInADay;
$hours = floor($hourSeconds / $secondsInAnHour);
$minuteSeconds = $hourSeconds % $secondsInAnHour;
$minutes = floor($minuteSeconds / $secondsInAMinute);
$remainingSeconds = $minuteSeconds % $secondsInAMinute;
$seconds = ceil($remainingSeconds);
$obj = array(
'd' => (int) $days,
'h' => (int) $hours,
'm' => (int) $minutes,
's' => (int) $seconds
);
return $obj;
}
这个函数给了我一个错误:
Parse error: syntax error, unexpected T_STRING on line 6
我这样称呼它:
$start = new DateTime('2010-10-12');
$end = new DateTime('2010-10-14');
$seconds = round(abs($end->format('U') - $start->format('U')));
$obj = secondsToTime($seconds);