【发布时间】:2021-04-29 18:32:01
【问题描述】:
我在 PHP 中使用“date”函数和“strtotime”时发现了一个奇怪的问题。
echo date('m/d/Y h:i:s a', time())."<br>"; //returns 04/29/2021 12:26:30 pm
echo date('M Y', strtotime('-5 months'))."<br>"; //returns Nov 2020
echo date('M Y', strtotime('-4 months'))."<br>"; //returns Dec 2020
echo date('M Y', strtotime('-3 months'))."<br>"; //returns Jan 2021
echo date('M Y', strtotime('-2 months'))."<br>"; //returns Mar 2021
echo date('M Y', strtotime('-1 months'))."<br>"; //returns Mar 2021
echo date('M Y')."<br>"; //returns Apr 2021
我的服务器时间是正确的,如第一行所示,但为什么 strtotime('-2 months') 和 strtotime('-1 months') 两次返回相同的值(2021 年 3 月)?
提前致谢
【问题讨论】:
-
任何大于一周的时间单位都没有一致的定义,即使这样,DST、闰年和闰秒也会让扳手混在一起。跨度>