/ Published in: PHP
URL: http://www.phpriot.com/d/code/date-time/duration/index.html
Expand |
Embed | Plain Text
Duration is a function used to turn seconds into a readable format, measured in weeks, days, hours, minutes and seconds. Highlight: PHP <?php function duration($secs) { 'd' => $secs / 86400 % 7, 'h' => $secs / 3600 % 24, 'm' => $secs / 60 % 60, 's' => $secs % 60); $added = false; foreach ($vals as $k => $v) { if ($v > 0 || $added) { $added = true; $ret[] = $v . $k; } } } ?> Sample usage Highlight: PHP <?php $dateOfBirth = $someTimestamp; ?>
Comments
Subscribe to comments
You need to login to post a comment.

nice man, cheers =)