使用Yii framework 2.0我从我的数据库中获取记录。在每个表格中,我都有一个名为 created_at 的列。假设 created_at ='2015-12-25 01:00:00' 。我使用以下Yii格式化程序。
Yii::$app->formatter->asDate($model->created, 'php:d-m-Y h:i:s');
结果是: 25-12-2015 02:00:00 。提前1小时。我不知道为什么。我应该配置什么来解决这个问题?
答案 0 :(得分:1)
'components' => [
'formatter' => [
'defaultTimeZone' => 'Europe/Paris',
],
],
答案 1 :(得分:0)
您应该在组件配置中设置格式化程序defaultTimeZone和timeZone,例如,如果您将UTC
存储在数据库中并希望显示Europe/Paris
:
'components' => [
'formatter' => [
'defaultTimeZone' => 'UTC',
'timeZone' => 'Europe/Paris',
],
],
了解详情:http://www.yiiframework.com/doc-2.0/guide-output-formatter.html#time-zones