ActiveRecord中是否有任何方法可以在连接时动态更改数据库的时区。
我把它和codeigniter一起使用。问题是我成功地更改了codeigniter中的时区,但它不会影响ActiveRecord查询。
提前谢谢。
设置默认时区(index.php(
date_default_timezone_set('America/New_York');
在型号中手动设置日期时间格式
static $datetime_format = 'Y-m-d H:i:s';
此外,尝试将其添加到初始化文件中(我猜您使用了sparks来安装php-activerecord(
//Include the ActiveRecord DateTime Class
require_once $spark_path.'vendor/php-activerecord/lib/DateTime.php';
//it should use your database time format, once you set it.
ActiveRecord'DateTime::$DEFAULT_FORMAT = 'db';