Created
July 16, 2017 07:43
-
-
Save Debashis-Sinha/2749672783c59393c956e18d48203fee to your computer and use it in GitHub Desktop.
php seconds to time
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
/** | |
* Seconds to time | |
* @param $sec | |
* @return string | |
*/ | |
static function secondsToTime( $sec ){ | |
if( !is_float( $sec ) ) $sec = floatval( $sec ); | |
$hours = floor($sec / 3600); | |
$minutes = floor(($sec - ($hours * 3600)) / 60); | |
$seconds = $sec - ($hours * 3600) - ($minutes * 60); | |
if ( $hours < 10 ) $hours = "0" . $hours; | |
if ( $minutes < 10 ) $minutes = "0" . $minutes; | |
if ( $seconds < 10 ) $seconds = "0" . $seconds; | |
$seconds = number_format( $seconds, 2, '.', '' ); | |
return $hours . ':' . $minutes . ':' . $seconds; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment