Skip to content

Instantly share code, notes, and snippets.

@cnicodeme
Last active September 25, 2015 08:27
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 cnicodeme/892200 to your computer and use it in GitHub Desktop.
Save cnicodeme/892200 to your computer and use it in GitHub Desktop.
Format seconds in h:m:s (output can be changed)
<?php
/**
* Create a DateTime object with the number of seconds
* Since the date starts at year 0, the returned time will be in year/month/day/hour/minute/second
*
* @param Integer $iTime : Timestamp in seconds
* @param String $sFormat (optional) : The date format to return
*
* @return String : The well formatted date.
*/
function timetostr ($iTime, $sFormat = 'H\hi\ms\s') {
$oTime = new DateTime ('@'.$iTime);
return $oTime->format ($sFormat);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment