Converting Seconds To dd:hh:mm:ss Format

Converting Seconds To dd:hh:mm:ss Format

Here is a simple function to write seconds in dd:hh:mm:ss:

  1. function sformat( s ) {
  2.       var fm = [
  3.                         Math.floor(Math.floor(Math.floor(s/60)/60)/24)%24,      //DAYS
  4.                         Math.floor(Math.floor(s/60)/60)%60,                          //HOURS
  5.                         Math.floor(s/60)%60,                                                //MINUTES
  6.                         s%60                                                                      //SECONDS
  7.                   ];
  8.       return $.map(fm,function(v,i) { return ( (v < 10) ? '0' : '' ) + v; }).join( ':' );
  9. }

Usage:
  1. var sf = sformat( 1450 );  //value of sf --> 00:00:24:10