简体   繁体   English

PHP strtotime在小于1900的日期返回false

[英]PHP strtotime returning false for dates less than 1900

I know this question is very popular 我知道这个问题非常受欢迎

Asked here PHP: strtotime is returning false for a future date? 在这里问到PHP:strtotime在未来的日期会返回false吗? and here How can I work with dates before 1900 in PHP? 在这里我如何在PHP中使用1900年之前的日期?

Could you please confirm my choices: 你能否确认一下我的选择:

  1. Upgrade to a 64bit architecture 升级到64位架构

  2. Replace the strtotime calls by DateTime + DateInterval We can't call DateTime->getTimestamp but we can use DateInterval to calculate the diff 用DateTime + DateInterval替换strtotime调用我们不能调用DateTime-> getTimestamp但我们可以使用DateInterval来计算diff

Do I have any other options? 我还有其他选择吗? Unfortunately, I can't pick option 2 because I am relying on ORM (Propel) + a lot of legacy code using strtotime. 不幸的是,我不能选择选项2,因为我依赖于ORM(Propel)+使用strtotime的许多遗留代码。 Refactoring this stuff + customizing the ORM generators could be more expensive than upgrading to 64bits. 重构这些东西+自定义ORM生成器可能比升级到64位更昂贵。

If anybody could confirm or offer any other options, that would be really appreciated. 如果有人可以确认或提供任何其他选择,那将非常感激。

Thanks 谢谢

The date format is the standard yyyy-mm-dd 日期格式是标准yyyy-mm-dd

PHP Version 5.3.2 PHP版本5.3.2

AFAIK, you are limited to these two solutions. AFAIK,您仅限于这两种解决方案。

You should update to 64-bit system if you can afford it, and if it solves a problem then that's better. 如果你能负担得起,你应该更新到64位系统,如果它解决了问题,那就更好了。

Edit: Just had to check: http://php.net/manual/en/function.runkit-function-redefine.php You could probably try and redefine strtotime() to work with dates prior to 1901. 编辑:只需要检查: http//php.net/manual/en/function.runkit-function-redefine.php您可以尝试重新定义strtotime()以使用1901年之前的日期。

You can use gregoriantojd, which has a date range of 4714 BC to 9999 AD A much wider range than 1900(1970)-2038. 您可以使用gregoriantojd,其日期范围为公元前4714年至公元9999年范围远大于1900(1970)-2038。 If you are trying to calculate date differences, they are close enough. 如果您正在尝试计算日期差异,那么它们就足够接近了。 Well, except for the "lost" 10 days October 4-14, 1582. And because of different leap year calculation, you will be off by a day every 100 years. 好吧,除了1582年10月4日至14日的“失去的”10天。由于不同的闰年计算,你将每100年休息一天。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM