对于小于 1900 的日期,PHP strtotime 返回 false

标签 php strtotime

我知道这个问题很受欢迎

在这里问 PHP: strtotime is returning false for a future date? 在这里 How can I work with dates before 1900 in PHP?

能否确认我的选择:

  1. 升级到 64 位架构

  2. 用 DateTime + DateInterval 替换 strtotime 调用 我们不能调用 DateTime->getTimestamp 但我们可以使用 DateInterval 来计算差异

我还有其他选择吗? 不幸的是,我不能选择选项 2,因为我依赖于 ORM (Propel) + 大量使用 strtotime 的遗留代码。重构这些东西 + 自定义 ORM 生成器可能比升级到 64 位更昂贵。

如果有人可以确认或提供任何其他选项,那将不胜感激。

谢谢

日期格式是标准的yyyy-mm-dd

PHP 版本 5.3.2

最佳答案

据我所知,您只能使用这两种解决方案。

如果你负担得起,你应该更新到 64 位系统,如果它能解决问题那就更好了。

编辑:只需检查: http://php.net/manual/en/function.runkit-function-redefine.php 您可能会尝试重新定义 strtotime() 以处理 1901 年之前的日期。

关于对于小于 1900 的日期,PHP strtotime 返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7198539/

相关文章:

php - 无法通过 cake cake db_config 创建数据库

php - 如何将 Laravel 项目插入 Apache Tomcat servlet?

php - 简化这个查询?

javascript - 在 PHP 和 Mysql 的 jquery 日期选择器中禁用给定范围内的日期

php - strtotime 函数传递错误的日期和时间格式的奇怪行为

php - strtotime() 有错误吗?

php - 如果行发生更改,MySQL 更改表更改列会抛出错误

php - 格式化时间无效

php - strtotime() 被认为是有害的?

php - strtotime() & date() 将日期转换为与以前相同的格式时出现奇怪的行为