Seconds to Hours, Minutes and Seconds (HH:MM:SS)

[vc_row][vc_column][vc_column_text]

[/vc_column_text][/vc_column][/vc_row][vc_row][vc_column][fenomen_title title=”Program”][vc_tta_tabs][vc_tta_section title=”C/C++” tab_id=”1577510003763-5ea0f726-9a80″][vc_column_text]

C/C++ Prpgram

void main(){

  int seconds=4545;

  //convret seconds into hr, min, sec
  int hr=(int)(seconds/3600);
  int min=((int)(seconds/60))%60;
  int sec=(int)(seconds%60);

  printf("%d:%d:%d",hr, min, sec);
}

Output:

1:15:45

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Java” tab_id=”1577510003869-86e3d8a8-6742″][vc_column_text]Java Program

class Simple{  
  public static void main(String args[]){  
       
    int seconds=4545;

    //convret seconds into hr, min, sec
    int hr=(int)(seconds/3600);
    int min=((int)(seconds/60))%60;
    int sec=(int)(seconds%60);

    System.out.println(hr+":"+min+":"+sec);
  }
}

Output

1:15:45

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Python” tab_id=”1577510096866-e8f6e878-1c44″][vc_column_text]

Python Program


seconds=4545

#convert seconds to hours, minutes and seconds
hr=int(seconds/3600)
min=int(seconds/60)%60
sec=int(seconds%60)

#formate time in hh:mm:ss format
hhmmss="%s:%s:%s"%(str(hr).zfill(2), str(min).zfill(2), str(sec).zfill(2))

print(hhmmss)

Output:

01:15:45

[/vc_column_text][/vc_tta_section][vc_tta_section title=”JavaScript” tab_id=”1577510109645-bf65ddf2-5764″][vc_column_text]

JavaScript Program


(function(){

seconds=4545;

/*convert seconds into hours, minutes and seconds*/
hr=Math.floor(seconds/3600);
min=Math.floor(seconds/60)%60;
sec=seconds%60;

/*padding leading zero if the number is single digit*/
hr=(hr< 10 ? '0' : '') + hr;
min=(min< 10 ? '0' : '') + min;
sec=(sec< 10 ? '0' : '') + sec;

return hr+':'+min+':'+sec;
})();

Output:

01:15:45

[/vc_column_text][/vc_tta_section][/vc_tta_tabs][/vc_column][/vc_row]