因此,似乎PHPActiveRecord正在格式化更新时间戳(对我来说)
当我打印更新日期时,它显示:
Wed, 05 Jun 2013 21:14:48 +0200
在数据库中的位置:
2013-06-23 20:04:18
为了100%确定,我使用PDO来检索记录,它显示的格式与我在数据库中看到的格式完全相同。
知道为什么会出现这种自动格式化吗?如果有办法纠正的话?
谢谢。
编辑
好吧,所以我发现了如何操作它:
$records->updated->format('Y-m-d');
然而,我仍然想知道为什么会发生这种情况,以及是否有默认设置的方法。
DateTime
的对象中。
通常情况下,您可以对任何DateTime
对象执行->format($yourformat)
,但对于phpactiverecord
子对象,如果不提供默认格式,则会使用该默认格式。
这个扩展还有一个toString()
函数,它调用这个format()
,所以您可以获得默认格式(顺便说一句,您可以在同一个类中设置它)。
查看PHPActiveRecord提供的DateTime.php
类以了解更多信息,但实际情况如下:
class DateTime extends 'DateTime{
public static $DEFAULT_FORMAT = 'rfc2822';
//array with formats here
public function format($format=null){
return parent::format(self::get_format($format));
}
public static function get_format($format=null){
//get default format if nothing is provided
}
public function __toString(){
//gets called when you use the object as a string
return $this->format();
}
}
您可以在全局范围内完成
代码段
ActiveRecord'Connection::$datetime_format = 'Y-m-d H:i:s';
ActiveRecord'DateTime::$DEFAULT_FORMAT = 'db';