1

这是关于 Symfony 1.4,可能是所有以前的版本,运行 php 5.3,mysql 5.1。

如果我将旧日期存储在 < 1970... 的数据库中,然后检索它们,它们会自动转换为不正确的日期。

示例表:

id, some_date
1, 1961-09-09

一个简单的例子。

$record = MyTablePeer::retrieveByPK(1);
echo $record->getSomeDate(); 
//returns: 09/09/61
//Want it to return: 1961-09-09

从哪里控制输出格式?我需要获取整个日期,并将整个年份存储在数据库中。

4

1 回答 1

4

日期字段获取器有一个$format参数,使用它,比如$record->getSomeDate("Y-m-d");.

此外,这就是 docblock 关于日期访问器的说法:

此访问器仅适用于 unix 纪元日期。如果您需要支持纪元前/纪元后日期,请考虑使用 propel.useDateTimeClass 构建或将此列类型更改为(已弃用的)“unix 之前”列类型(例如 BU_TIMESTAMP 或 BU_DATE)。

@param      string $format The date/time format string (either date()-style or strftime()-style).
             If format is NULL, then the integer unix timestamp will be returned. 
@return     mixed Formatted date/time value as string or (integer) unix timestamp (if format is NULL).

@throws     PropelException - if unable to convert the date/time to timestamp.
于 2010-09-09T21:50:20.870 回答