|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-09-16 15:12 UTC] requinix@php.net
-Status: Open
+Status: Not a bug
[2016-09-16 15:12 UTC] requinix@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 19 17:00:01 2025 UTC |
Description: ------------ strftime(%G) for Jan 1st 2017 returns 2016 instead of 2017. trying with other years works as expected (2013..2015 and 2018..2020) but others do not (2005, 2006, 2010..2012, 2016, 2017). these lists are not exhaustive. tested on 7.0.10 and 5.6.7 php versions. the date function works as expected. here's a second 19-line script that looks for the first January day where %G works as expected: ----------------- <?php echo "php version: " . phpversion() . "\n"; for ($year=1970;$year<2030;$year++) { $day = 1; $seconds = mktime(0,0,0,1,$day,$year); while ( strftime("%G",$seconds) != $year ) { $day ++; $seconds = mktime(0,0,0,1,$day,$year); } if ($day == 1) echo "$year: ok\n"; else echo "$year: it is not $year until " . strftime("%c",$seconds) . "\n"; } ---------------------------------- thanks. Test script: --------------- <?php echo "php version: " . phpversion() . "\n"; $seconds = mktime(0,0,0,1,1,2017); echo "seconds from epoch: $seconds\n"; echo "strftime(%G): " . strftime("%G",$seconds) . "\n"; echo "strftime(%c): " . strftime("%c",$seconds) . "\n"; echo "date(Y) : " . date("Y",$seconds) . "\n"; ?> Expected result: ---------------- php version: 7.0.10-1 seconds from epoch: 1483225200 strftime(%G): 2017 strftime(%c): Sun Jan 1 00:00:00 2017 date(Y) : 2017 Actual result: -------------- php version: 7.0.10-1 seconds from epoch: 1483225200 strftime(%G): 2016 strftime(%c): Sun Jan 1 00:00:00 2017 date(Y) : 2017