gpt4 book ai didi

php - 在 PHP 5.3 中定义时间戳的新方法?

转载 作者:可可西里 更新时间:2023-11-01 00:51:02 24 4
gpt4 key购买 nike

PHP 5.3 是否有新的方法来定义时间戳?

这个 strtotime('0000-00-00');

将在 PHP 5.3 之前的版本中返回 0 date(01/01/1970),在 PHP 5.3 中返回 -62169984000。还有像 30/11/-0001 这样的日期!!

但我在文档中找不到任何相关解释。有什么想法是改变了还是我遗漏了什么?

最佳答案

解释在这里:https://bugs.php.net/bug.php?id=46597

引用:

Sure, but strtotime() has long handled invalid month and day values the same way as mktime() by effectively "rounding" them into valid values: the 0th day of the month becomes the last day of the previous month, the 0th month is the last month of the previous year, and so on. Given that interpretation, 0000-00-00 fairly obviously becomes the last day of November in the year -1 (better known as 2 BCE).

There's no chance that behaviour is going to be changed now: checkdate() is a much better way of sniffing out invalid dates anyway, and it would be a potentially nasty backward compatibility break for people relying on this behaviour in strtotime().

关于php - 在 PHP 5.3 中定义时间戳的新方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7272999/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com