我尝试这样做,echo date("Y", strtotime("1999-00-00"));
而不是1999
返回1998
.有办法怎么处理这个?我更喜欢"干净的方式",不喜欢$finalYear = (float)$year+1
等等.日期格式必须是YYYY-00-00
(带零)
如果您完全确定日期的格式永远不会改变,那么您最好还是选择
echo substr('1999-00-00', 0, 4);
Run Code Online (Sandbox Code Playgroud)
而不是在整个日期/时间子系统中引发strtotime()和往返的繁重开销.
当你告诉PHP的日期函数时,月/日是0,这是"无效",它会将它们转换为适当的"之前"值.
例如
1999-00-10 is actually 1998-12-10
1999-11-00 is actually 1999-10-31
Run Code Online (Sandbox Code Playgroud)
等等.这就像说"昨天"或"上个月".同样,指定第13个月就可以了
1999-13-01 is actually 2000-01-01
Run Code Online (Sandbox Code Playgroud)