phpで日付、分、秒に変換するサンプル
phpコード:
function seconds2days($mysec) {
$mysec = (int)$mysec;
if ( $mysec === 0 ) {
return '0 second’;
}
$mins = 0;
$hours = 0;
$days = 0;
if ( $mysec >= 60 ) {
$mins = (int)($mysec / 60);
$mysec = $mysec % 60;
}
if ( $mins >= 60 ) {
$hours = (int)($mins / 60);
$mins = $mins % 60;
}
if ( $hours >= 24 ) {
$days = (int)($hours / 24);
$hours = $hours % 60;
}
$output = ";
if ($days){
$output .= $days." days “;
}
if ($hours) {
$output .= $hours." hours “;
}
if ( $mins ) {
$output .= $mins." minutes “;
}
if ( $mysec ) {
$output .= $mysec." seconds “;
}
$output = rtrim($output);
return $output;
}