Convert Seconds To HH:MM:SS


/ Published in: PHP
Save to your folder(s)

This came in handy when I was working with Hour / Minute / Second dropdown on a page.


Copy this code and paste it in your HTML
  1. function seconds($seconds) {
  2.  
  3. // CONVERT TO HH:MM:SS
  4. $hours = floor($seconds/3600);
  5. $remainder_1 = ($seconds % 3600);
  6. $minutes = floor($remainder_1 / 60);
  7. $seconds = ($remainder_1 % 60);
  8.  
  9. // PREP THE VALUES
  10. if(strlen($hours) == 1) {
  11. $hours = "0".$hours;
  12. }
  13.  
  14. if(strlen($minutes) == 1) {
  15. $minutes = "0".$minutes;
  16. }
  17.  
  18. if(strlen($seconds) == 1) {
  19. $seconds = "0".$seconds;
  20. }
  21.  
  22. return $hours.":".$minutes.":".$seconds;
  23.  
  24. }

URL: http://www.aristoworks.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.