PHP 的 strtotime() 出现这种情况咋解释
为什么 strftime 解析出来的第 0 周,用 strtotime 解析却失败?看 strtotime 的文档:
Description: ISO year with ISO weekFormat: YY "-"? "W" WExamples: "2008W27", "2008-W28"strtotime 里的「??-W??」格式,W 前面应该是 ISO Year、后面应该接 ISO Week。所以为什么要画蛇添足在「年」「周」前面写上「ISO」,是为了装逼显得自己很专业吗?我们来看 strftime 的文档:
%g Two digit representation of the year going by ISO-8601:1988 standards (see %V)%G The full four-digit version of %g%V ISO-8601:1988 week number of the given year, starting with the first week of the year with at least 4 weekdays, with Monday being the start of the week 01 through 53 (where 53 accounts for an overlapping week)你看,%Y 和 %G 出来的是两种「年」,%W 和 %V 出来的是两种「周」,加不加 ISO 确实是有区别的。strtotime 里的 W 前后需要的是 %G 和 %V 的输出。拿 %Y 和 %W 的输出写进去,可不就是拿前朝的剑斩本朝的官么?echo strftime("%G-%V", strtotime("2016-01-01")); // 输出 2015-53echo strftime("%Y-%m-%d", strtotime("2015-W53")); // 输出 2015-12-28(当周第一天)即:公历的 2016 年 1 月 1 日,还在 ISO 2015 年的第 53 周(2015-12-28 ~ 2016-01-03)。
后面的疑问同理,ISO 年和公历的年不同、ISO 周和公历的周不同。
p.s. 关于问题里提到的「第 0 周」,其实你也用不着观察和猜想,看 strftime 的文档就可以知道标准答案了:
%W A numeric representation of the week of the year, starting with the first Monday as the first week.有疑问还是先看文档吧。
■网友
strptime — Parse a time/date generated with strftime()
■网友
【PHP 的 strtotime() 出现这种情况咋解释】 初步看了你这个问题的描述,应该是PHP的时区没有设置对,你打开php.ini文件,找到date.timezone这个配置,然后设置为date.timezone = Asia/Shanghai,就可以了。
推荐阅读
- 如果你的多肉出现这个长势,要注意这个细节,多肉才会越来越美!
- 『天气』多条高速、航道封闭管制 江苏出现强浓雾天气
- 内蒙古呼伦贝尔出现零下43.6摄氏度极寒天气
- |高压补水脸部出现红肿,网红“补水神器”靠谱吗?
- 肝硬化|肝不好,身体会出现\3黑2疼\,医生直言:小心\肝硬化\找上门
- 脑梗|神经内科专家:脑梗“到访”前,身体或会出现3种异常,别忽视
- 坐标合肥,请问在哪里能捕捉到程序员这种生物他们大都出现在哪里呢
- 关于用phpfsocket 写Post, 模拟http 报文怎样写入要传输的处理数据
- 孕妇|多半是贫血了,需尽早应对!孕妇身体出现以下4个异常
- 胃病|饭后胃部出现4种不适时,要及时检查,以免“拖”成胃病,别忽视
