/ Published in: PHP

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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; echo 'I am ' . duration($ageInSeconds) . ' old'; ?>
URL: http://www.phpriot.com/d/code/date-time/duration/index.html
Comments
