Created_at使用错误的时区保存

时间:2015-03-31 10:48:11

标签: laravel

我有一个laravel应用程序,我试图将用户签入和签出保存到我​​的数据库

我有一个模型Checkins,我将其记录为created_at和updated_at

在我的本地主机上它保存了我的timezome(埃及)的正确时间,我试图将app.php文件更改为以下

    |--------------------------------------------------------------------------
| Application Timezone
|--------------------------------------------------------------------------
|
| Here you may specify the default timezone for your application, which
| will be used by the PHP date and date-time functions. We have gone
| ahead and set this to a sensible default for you out of the box.
|
| This is a bad thing really i think there is a problem within the server, the datetime
*/

'timezone'        => 'EET',

它在我的本地主机上工作得很好并且保存在当前正确的时间,因为生产它以UTC时区保存

当我在生产终端中写入命令日期date时,我得到以下内容

Tue Mar 31 12:46:38 EET 2015

我检查了mysql的时区,发现它从系统时间中获取时间

SELECT @@global.time_zone, @@session.time_zone;
SYSTEM

这里有什么问题?

更新:

我创建了一个包含date('H:i:s');的php页面,并打印出合适的时间

5 个答案:

答案 0 :(得分:6)

要设置Laravel应用的时区,请更改'timezone'

中的config/app.php
|--------------------------------------------------------------------------
| Application Timezone
|--------------------------------------------------------------------------
|
| Here you may specify the default timezone for your application, which
| will be used by the PHP date and date-time functions. We have gone
| ahead and set this to a sensible default for you out of the box.
|
| This is a bad thing really i think there is a problem within the server, the datetime
*/

'timezone'        => 'America/Los_Angeles',

您可以找到所需的时区here

答案 1 :(得分:0)

根据php documentation强烈建议您为所在位置使用正确的时区,例如Asia/ShanghaiAustralia/Perth不使用EET或{{1} }。

您可以找到您所在位置的时区here

答案 2 :(得分:0)

也许您使用insertinsertGetId来插入数据?

如果使用Eloquent(like ->save())插入数据,时间就会正确。

答案 3 :(得分:0)

您必须在config/app.php

中更改您的时区

here,您必须运行以下命令来保存您的时区更改:

php artisan cache:clear php artisan view:clear php artisan config:cache

答案 4 :(得分:-2)

看起来你忘了运行php artisan config:cache。

相关问题