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;
}
這個功能給予的我一個錯誤:語法意外T_STRING
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);
除了在發佈的代碼中丟失的評論,第六行沒有字符串。發佈代碼你調用這個函數 –
抱歉,該錯誤,更新,它仍然give'me該錯誤 –
那麼什麼是第6行? –