[英]php get correct date by week one of the year using strtotime
I used this code to get the 1st date, of the 1st week, of the year: 我使用以下代码获取一年中第一周的第一天日期:
echo date('Y-m-d',strtotime('2018W01')); #JAN 1 is Monday, returned 01/01
echo date('Y-m-d',strtotime('2013W01')); #JAN 1 is Tuesday, returned 12/31
echo date('Y-m-d',strtotime('2014W01')); #JAN 1 is Wednesday, returned 12/30
echo date('Y-m-d',strtotime('2015W01')); #JAN 1 is Thursday, returned 12/29
echo date('Y-m-d',strtotime('2016W01')); #JAN 1 is Friday, returned 01/04!? (shouldn't it be 12/28)
echo date('Y-m-d',strtotime('2022W01')); #JAN 1 is Saturday, returned 01/03!? (shouldn't it be 12/27)
echo date('Y-m-d',strtotime('2017W01')); #JAN 1 is Sunday, returned 01/02!? (shouldn't it be 12/26)
Since PHP, which is greater than 5.2.7, showing me that Monday is the 1st day of the week, then I was hoping that the year 2017, 1st day of week, should be 12/26. 由于PHP(大于5.2.7)向我显示星期一是一周的第一天,因此我希望2017年(一周的第一天)应该为12/26。 Is there a week number configuration somewhere for PHP to display 1st day, of the week, of the year correctly, for every year? PHP是否有某周的数字配置可以正确显示每年的每年的第一天? TIA TIA
echo date('Y-m-d',strtotime('2016W01'));
#JAN 1 is Friday, returned 01/04!? (shouldn't it be 12/28)
No, it shouldn't be 12/28, because first week of the year has this rules: 不,不应该是12/28,因为一年的第一周有以下规则:
If 1 January is on a Monday, Tuesday, Wednesday or Thursday, it is in week 01. If 1 January is on a Friday, it is part of week 53 of the previous year; 如果1月1日在星期一,星期二,星期三或星期四,则在第01周。如果1月1日在星期五,则是上一年的第53周; if on a Saturday, it is part of week 52 (or 53 if the previous year was a leap year); 如果在星期六,则是第52周的一部分(如果前一年是a年,则为53); if on a Sunday, it is part of week 52 of the previous year. 如果在星期日,则是上一年第52周的一部分。
Other examples are also correct. 其他示例也是正确的。 Read more here . 在这里阅读更多。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.