note 110877 added to function.strtotime
| From: | jimmetry at gmail dot com | Date: | Tue, 18 Dec 2012 12:39:47 +0000 |
| Subject: | note 110877 added to function.strtotime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-192580@lists.php.net to get a copy of this message | ||
Comparing two simple times (no date) is way too much effort with strtotime, especially with the new
epoch and timezone warnings. I got tired of making the problem overcomplicated, and made this little
function instead:
<?php
/* Converts a string time duration into seconds. Supports
* hours:minutes:seconds, hours:minutes:seconds.fraction,
* hours:minutes and minutes:seconds.fraction formats.
*/
function durationInSeconds($duration) {
// Split components
$pieces = explode(':', $duration);
$numPieces = count($pieces);
// Check for hours:minutes anomaly
if ($numPieces == 3 || strpos($pieces[$numPieces - 1], '.'))
$offset = 0;
else $offset = 1;
// Sum components
$seconds = 0;
for ($i = 0, $j = $numPieces - 1; $j >= 0; $i++, $j--)
$seconds += $pieces[$i] * pow(60, $j + $offset);
return $seconds;
}
?>
----
Server IP: 69.147.83.199
Probable Submitter: 115.64.209.221
----
Manual Page -- http://php.net/manual/en/function.strtotime.php
Edit -- https://master.php.net/note/edit/110877
Del: integrated -- https://master.php.net/note/delete/110877/integrated
Del: useless -- https://master.php.net/note/delete/110877/useless
Del: bad code -- https://master.php.net/note/delete/110877/bad+code
Del: spam -- https://master.php.net/note/delete/110877/spam
Del: non-english -- https://master.php.net/note/delete/110877/non-english
Del: in docs -- https://master.php.net/note/delete/110877/in+docs
Del: other reasons-- https://master.php.net/note/delete/110877
Reject -- https://master.php.net/note/reject/110877
Search -- https://master.php.net/manage/user-notes.php