Skip to content

Instantly share code, notes, and snippets.

@youssman
Created October 21, 2014 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save youssman/72a23c96483f53c54c09 to your computer and use it in GitHub Desktop.
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
<?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