我不确定这是一个错误,因为搜索后我找不到任何重复的经历 – 但是,这个让我难过.
虽然在一个(相当痛苦的)脚本中打算采取一堆自由文本记录并将它们转换为有用的日期记录,但我信任的朋友strtotime()似乎让我失望了.
出于测试目的,我将代码简化为:
=date('Y', strtotime("1999"));?>
输出显示:1999年
=date('Y', strtotime("1981"));?>
输出显示:1981年
=date('Y', strtotime("2001"));?>
输出显示:2012年
=date('Y', strtotime("2021"));?>
输出显示:2012年
在输入超过“1999”之前,一切似乎都很好 – 从那一点开始,每一年之前和之后每年都会返回当前年份(2012年)
任何输入都非常感谢.
解决方法:
The “Year (and just the year)” format only works if a time string has already been found — otherwise this format is recognised as HH MM.
(页面上的最后一个注释).
标签:strtotime,php
来源: https://codeday.me/bug/20190826/1730703.html