我对日期时间差异有一个很大的问题。当我比较2019-12-01和2019-11-01这两个日期时,只有30天的差异,没有月份,为什么?
$date2 = new DateTime('2019-12-01');
$date1 = new DateTime("2019-11-01");
$diff = $date1->diff($date2, true)->m;
echo "Difference should be 1 month: ".$diff;发布于 2020-01-27 19:58:01
这样做
$date2 = new DateTime("2019-12-01T00:00:00Z");
$date1 = new DateTime("2019-11-01T00:00:00Z");
$diff = $date1->diff($date2, true)->m;
echo "Difference should be 1 month: ".$diff;T实际上并不代表任何东西。它只是ISO 8601 combined date-time格式所需的分隔符。你可以把它理解为时间的缩写。
Z代表零时区,因为它与Coordinated Universal Time (UTC)的偏移量为0。
解释here
请在此处查看demo
https://stackoverflow.com/questions/59930489
复制相似问题