note 78025 added to ref.datetime

From: Date: Mon, 24 Sep 2007 20:25:45 +0000
Subject: note 78025 added to ref.datetime
Groups: php.notes 
Request: Send a blank email to php-notes+get-130753@lists.php.net to get a copy of this message
I wrote a simple script to format a duration in seconds. Give the function some value in seconds and it will return an array. <?php function format_duration($seconds) { $periods = array( 'centuries' => 3155692600, 'decades' => 315569260, 'years' => 31556926, 'months' => 2629743, 'weeks' => 604800, 'days' => 86400, 'hours' => 3600, 'minutes' => 60, 'seconds' => 1 ); $durations = array(); foreach ($periods as $period => $seconds_in_period) { if ($seconds >= $seconds_in_period) { $durations[$period] = floor($seconds / $seconds_in_period); $seconds -= $durations[$period] * $seconds_in_period; } } return $durations; } echo format_duration(864); /* [minutes] => 14 [seconds] => 24 */ echo format_duration(3600); /* [hours] => 1 */ echo format_duration(11111111); /* [months] => 4 [days] => 6 [hours] => 20 [minutes] => 28 [seconds] => 59 */ ?> ---- Server IP: 69.147.83.197 Probable Submitter: 75.153.221.123 ---- Manual Page -- http://www.php.net/manual/en/ref.datetime.php Edit -- https://master.php.net/note/edit/78025 Del: integrated -- https://master.php.net/note/delete/78025/integrated Del: useless -- https://master.php.net/note/delete/78025/useless Del: bad code -- https://master.php.net/note/delete/78025/bad+code Del: spam -- https://master.php.net/note/delete/78025/spam Del: non-english -- https://master.php.net/note/delete/78025/non-english Del: in docs -- https://master.php.net/note/delete/78025/in+docs Del: other reasons-- https://master.php.net/note/delete/78025 Reject -- https://master.php.net/note/reject/78025 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#130753) next »