为什么 Doctrine 不喜欢旧日期?
Exception was thrown : Could not convert database value "1876-01-01 00:00:00-00:00:00" to Doctrine Type datetime
还有一个:
Exception was thrown : Could not convert database value "0000-00-00 00:00:00-00:00:00" to Doctrine Type datetime
在我的实体中,我确实覆盖了 datetime
和 datetimetz
Type::overrideType('datetime', 'Doctrine\DBAL\Types\VarDateTimeType');
Type::overrideType('datetimetz', 'Doctrine\DBAL\Types\VarDateTimeType');
如果我将日期更新为 1976-01-01 00:00:00-00:00:00
,它工作正常。
更新:
所以我正在运行 Ubuntu 12.04 64 位,我也知道我有 64 位 time_t 从这些测试中工作:
strtotime() produces different output on 32 and 64 bit systems running PHP 5.3.3 (as mentioned previously). This affects the "zero date" ("0000-00-00 00:00:00") as well as dates outside the traditional 32 date range.
测试:
strtotime("0000-00-00 00:00:00") returns FALSE on a 32 bit system.
strtotime("0000-00-00 00:00:00") returns -62169955200 on a 64 bit system.
当执行 echo strtotime("0000-00-00 00:00:00");
时,我明白了:
php time_test.php -62169966000
那么 Doctrine 有问题吗?
最佳答案
PHP 中的纪元是 1970 或 1901,具体取决于您的系统。
来自 PHP 手册:
The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer). However, before PHP 5.1.0 this range was limited from 01-01-1970 to 19-01-2038 on some systems (e.g. Windows).
关于php - 无法将数据库值 "1876-01-01 00:00:00-00:00:00"转换为 Doctrine 类型日期时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14708763/