Created
October 21, 2014 09:51
-
-
Save youssman/72a23c96483f53c54c09 to your computer and use it in GitHub Desktop.
Give the days, hours, minutes, and seconds for a passed-in seconds value
This file contains hidden or 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
<?php | |
// 137 seconds => 2min 17s | |
protected function _timeConversion( $seconds ) { | |
$datetime = new DateTime('@' . $seconds, new DateTimeZone('UTC')); | |
$formatted = array( 'd' => $datetime->format('z'), | |
'h' => $datetime->format('G'), | |
'min' => $datetime->format('i'), | |
's' => $datetime->format('s') | |
); | |
$result = ''; | |
foreach ($formatted as $key => $value) { | |
if( $value != "0" ) { | |
$result .= $value . $key . ' '; | |
} | |
} | |
return rtrim($result); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment