开发者

New way of defining timestamp in PHP 5.3?

开发者 https://www.devze.com 2023-04-01 16:54 出处:网络
Is there a new approach in PHP 5.3 to define timestamp? this strtotime(\'0000-00-00\'); will return 0 date(01/01/1970) in PHP prior 5.3 and -62169984000 in PHP 5.3. And a date like 30/11/-0001 !!

Is there a new approach in PHP 5.3 to define timestamp?

this strtotime('0000-00-00');

will return 0 date(01/01/1970) in PHP prior 5.3 and -62169984000 in PHP 5.3. And a date like 30/11/-0001 !!

But I could not find any explanations about that in the do开发者_Go百科cumentation. Any idea was that changed or I am missing something?


Explanation is here: https://bugs.php.net/bug.php?id=46597

To Quote:

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().

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号