|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-05-29 23:07 UTC] omg00dness at yahoo dot com
Description:
------------
For an American timezone (at least those that observe Daylight Savings Time), strtotime() is outputting incorrectly when adding a negative time string.
Example uses March 11, 2012 at 2:00am, where the local time jumps instead to 3:00am.
Test script:
---------------
<?php
date_default_timezone_set('America/Los_Angeles');
echo date("M j Y H:i:s I", strtotime("2012-03-11 5:00:00 -1 hour")) . "\n";
echo date("M j Y H:i:s I", strtotime("2012-03-11 4:00:00 -1 hour")) . "\n";
echo date("M j Y H:i:s I", strtotime("2012-03-11 3:00:00 -1 hour")) . "\n";
echo date("M j Y H:i:s I", strtotime("2012-03-11 3:01:00 -1 hour")) . "\n";
echo date("M j Y H:i:s I", strtotime("2012-03-11 2:59:00 -1 hour")) . "\n";
echo date("M j Y H:i:s I", strtotime("2012-03-11 1:00:00 +1 hour")) . "\n";
echo date("M j Y H:i:s I", strtotime("2012-03-11 0:00:00 +1 hour")) . "\n";
?>
Expected result:
----------------
Mar 11 2012 04:00:00 1
Mar 11 2012 03:00:00 1
Mar 11 2012 01:00:00 0
Mar 11 2012 01:01:00 0
Dec 31 1969 16:00:00 0 //Perhaps output false?
Mar 11 2012 03:00:00 1
Mar 11 2012 01:00:00 0
Actual result:
--------------
Mar 11 2012 04:00:00 1
Mar 11 2012 03:00:00 1
Mar 11 2012 03:00:00 1
Mar 11 2012 03:01:00 1
Mar 11 2012 01:59:00 0
Mar 11 2012 03:00:00 1
Mar 11 2012 01:00:00 0
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 20:00:01 2025 UTC |
Improved test script: <?php date_default_timezone_set('America/Los_Angeles'); echo strtotime("2012-03-11 5:00:00 -1 hour") . "\t"; echo date("M j Y H:i:s I", strtotime("2012-03-11 5:00:00 -1 hour")) . "\n"; echo strtotime("2012-03-11 4:00:00 -1 hour") . "\t"; echo date("M j Y H:i:s I", strtotime("2012-03-11 4:00:00 -1 hour")) . "\n"; echo strtotime("2012-03-11 3:00:00 -1 hour") . "\t"; echo date("M j Y H:i:s I", strtotime("2012-03-11 3:00:00 -1 hour")) . "\n"; echo strtotime("2012-03-11 3:01:00 -1 hour") . "\t"; echo date("M j Y H:i:s I", strtotime("2012-03-11 3:01:00 -1 hour")) . "\n"; echo strtotime("2012-03-11 2:59:00 -1 hour") . "\t"; echo date("M j Y H:i:s I", strtotime("2012-03-11 2:59:00 -1 hour")) . "\n"; echo strtotime("2012-03-11 1:00:00 +1 hour") . "\t"; echo date("M j Y H:i:s I", strtotime("2012-03-11 1:00:00 +1 hour")) . "\n"; echo strtotime("2012-03-11 0:00:00 +1 hour") . "\t"; echo date("M j Y H:i:s I", strtotime("2012-03-11 0:00:00 +1 hour")) . "\n"; ?> My server produced (PHP Version 5.3.13): 1331463600 Mar 11 2012 04:00:00 1 1331460000 Mar 11 2012 03:00:00 1 1331460000 Mar 11 2012 03:00:00 1 1331460060 Mar 11 2012 03:01:00 1 1331459940 Mar 11 2012 01:59:00 0 1331460000 Mar 11 2012 03:00:00 1 1331456400 Mar 11 2012 01:00:00 0 http://www.alpha7f.com/phpt/bug62185.php