Since you already have a length in seconds, you can simply calculate it:
function timeLength($sec) { $s=$sec % 60; $m=(($sec-$s) / 60) % 60; $h=floor($sec / 3600); return $h.":".substr("0".$m,-2).":".substr("0".$s,-2); } echo timeLength(6534293);
If you really want to use a DateTime object, here (kind of cheating):
function dtLength($sec) { $t=new DateTime("@".$sec); $r=new DateTime("@0"); $i=$t->diff($r); $h=intval($i->format("%a"))*24+intval($i->format("%H")); return $h.":".$i->format("%I:%S"); } echo dtLength(6534293);
If you need this OO and don't mind creating your own class, you can try
class DTInterval { private $sec=0; function __construct($s){$this->sec=$sec;} function formet($format) { $rst=str_replace("H",$h,$format); return $rst; } }
source share