How does php date calculate the week? does php have BUG??

you can try it,

$str = strtotime ("2018-12-31");
echo date ("Yee, $str), date ("Waring, $str);
echo"
";
$str = strtotime ("2015-12-31");
echo date ("Yee, $str), date ("Waring, $str);

2018-12-31 is the first week, and 2015-12-31 is the 53rd week, which is why

Php
Jun.24,2021

this is not the reason why bug, appears like this because, according to the international standard "representation of the date and time of exchange of information in the form of data storage and exchange", the days at the beginning or end of the year may not belong to the first or last week of the year. December 31, 18 is Monday, not the last week of 18 years, but the first week of 19 years


look at the documents, we can see that the week of W is according to the ISO-8601 standard, that is, the week of January 4th is the first week of the year (or the first Thursday of the year is the first week of the year, these two statements are equivalent). If you want to use W , then the year should use o instead of Y .

Menu