strtotime 到特定日期的时间问题
strtotime to time issue with a specific date
我对以下代码有一个奇怪的行为:
echo strftime('%B %G', strtotime('2017-01-01')) . ' - weird..';
echo '<br>';
echo strftime('%B %G', strtotime('2017-01-02')) . ' - all good!';
结果:
January 2016 - weird..
January 2017 - all good!
我不知道为什么日期 2017-01-01 给我这个错误的结果。
我预计 2017 年 1 月 显然。
有什么见解吗?
啊有趣的 ;)
尽你所能 read in the doc:
%g Two digit representation of the year going by ISO-8601:1988 standards (see %V)
按 ISO-8601:1988 表示按周。
因此,如果您查看日历,2017-01-01 是星期日。你可以这样验证:
➜ ~ php -r "echo strftime('%u', strtotime('2017-01-01'));"
7%
所以2017-01-01属于2016年的最后一周!
您将对 2016-01-01、2016-01-02 和 2016-01-03
有相同的行为
➜ ~ php -r "echo strftime('%B %G', strtotime('2016-01-03'));"
January 2015%
为了安全起见,使用%Y
我对以下代码有一个奇怪的行为:
echo strftime('%B %G', strtotime('2017-01-01')) . ' - weird..';
echo '<br>';
echo strftime('%B %G', strtotime('2017-01-02')) . ' - all good!';
结果:
January 2016 - weird..
January 2017 - all good!
我不知道为什么日期 2017-01-01 给我这个错误的结果。 我预计 2017 年 1 月 显然。
有什么见解吗?
啊有趣的 ;)
尽你所能 read in the doc:
%g Two digit representation of the year going by ISO-8601:1988 standards (see %V)
按 ISO-8601:1988 表示按周。 因此,如果您查看日历,2017-01-01 是星期日。你可以这样验证:
➜ ~ php -r "echo strftime('%u', strtotime('2017-01-01'));"
7%
所以2017-01-01属于2016年的最后一周! 您将对 2016-01-01、2016-01-02 和 2016-01-03
有相同的行为➜ ~ php -r "echo strftime('%B %G', strtotime('2016-01-03'));"
January 2015%
为了安全起见,使用%Y