Last active
March 24, 2019 21:13
-
-
Save hidonet/de9c994bea0c1d45418119e53f92d460 to your computer and use it in GitHub Desktop.
Converts seconds to detailted time string...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function secondsToTime($sec) { | |
$ret_str = ''; | |
$day_length = 60 * 60 * 24; | |
$hour_length = 60 * 60; | |
$minute_length = 60; | |
if ($sec < 1) | |
{ | |
return ''; | |
} // eof if | |
if ($sec > $day_length) /// Day | |
{ | |
$cd = intval( $sec / $day_length); | |
$sec = $sec % $day_length; | |
$ret_str.= $cd.($cd > 1?'days':'day'); | |
} // eof if | |
if ($sec > $hour_length) /// Hour | |
{ | |
$cd = intval( $sec / $hour_length); | |
$sec = $sec % $hour_length; | |
$ret_str.= $cd.($cd > 1?'hours':'hour'); | |
} // eof if | |
if ($sec > $minute_length) /// Minute | |
{ | |
$cd = intval( $sec / $minute_length); | |
$sec = $sec % $minute_length; | |
$ret_str.= $cd.($cd > 1?'minutes':'minute'); | |
} // eof if | |
if ($sec > 0) /// Minute | |
{ | |
$cd = $sec; | |
$ret_str.= $cd.($cd > 1?'seconds':'second'); | |
} // eof if | |
return $ret_str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment