PHP ActiveRecord自动格式化日期
因此,PHPActiveRecord似乎正在格式化更新时间戳(对我来说) 当我打印更新的日期时,它显示:PHP ActiveRecord自动格式化日期,php,phpactiverecord,Php,Phpactiverecord,因此,PHPActiveRecord似乎正在格式化更新时间戳(对我来说) 当我打印更新的日期时,它显示: 2013年6月5日星期三21:14:48+0200 在DB中,我得到: 2013-06-23 20:04:18 为了100%确定,我使用PDO检索记录,它显示的格式与我在数据库中看到的格式完全相同 知道为什么会发生这种自动格式化吗?如果有办法纠正它呢 谢谢 编辑 好的,我发现了如何操作它: $records->updated->format('Y-m-d') 但是,我仍然想知道它发生的原因,
2013年6月5日星期三21:14:48+0200
在DB中,我得到:
2013-06-23 20:04:18
为了100%确定,我使用PDO检索记录,它显示的格式与我在数据库中看到的格式完全相同
知道为什么会发生这种自动格式化吗?如果有办法纠正它呢
谢谢
编辑
好的,我发现了如何操作它:
$records->updated->format('Y-m-d')代码>
但是,我仍然想知道它发生的原因,以及是否有一种默认设置方法。phpactiverecord检索它并将其存储在扩展DateTime
的对象中
通常,您可以对任何DateTime
对象执行->format($yourformat)
,但对于phpactiverecord
子对象,如果不提供默认格式,则会使用默认格式
此扩展还有一个调用此format()
的toString()
函数,因此您可以获得默认格式(顺便说一下,您可以在同一个类中设置)
查看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();
}
}
phpactiverecord检索它并将其存储在扩展DateTime
的对象中
通常,您可以对任何DateTime
对象执行->format($yourformat)
,但对于phpactiverecord
子对象,如果不提供默认格式,则会使用默认格式
此扩展还有一个调用此format()
的toString()
函数,因此您可以获得默认格式(顺便说一下,您可以在同一个类中设置)
查看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';
你可以在全球范围内做到这一点
代码片段
ActiveRecord\Connection::$datetime_format = 'Y-m-d H:i:s';
ActiveRecord\DateTime::$DEFAULT_FORMAT = 'db';