Converting second to readable time


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

This code is applied from http://www.ultramegatech.com/blog/2009/06/snippet-converting-seconds-to-readable-time/


Copy this code and paste it in your HTML
  1. function formatTime($secs) {
  2. $time = '';
  3. foreach (array(3600, 60, 1) as $i => $sec) {
  4. $time .= sprintf('%02d', floor($secs / $sec)).($i < 2 ? ':' : '');
  5. $secs = $secs % $sec;
  6. }
  7. return $time;
  8. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.