Created_at使用错误的时区保存

oso*_*sos 8 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',
Run Code Online (Sandbox Code Playgroud)

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

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

Tue Mar 31 12:46:38 EET 2015
Run Code Online (Sandbox Code Playgroud)

我检查了mysql的时区,我发现它从系统时间得到的时间

SELECT @@global.time_zone, @@session.time_zone;
SYSTEM
Run Code Online (Sandbox Code Playgroud)

这有什么不对?

更新:

我创建了一个php页面,date('H:i:s');并且打印出正确的时间

Art*_*gio 9

要设置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',
Run Code Online (Sandbox Code Playgroud)

你可以在这里找到你需要的时区.

  • 我只是使用`'timezone'=> date_default_timezone_get()`,所以我不必担心两个地方的时区。 (3认同)

bat*_*tsz 5

您必须更改您的时区config/app.php

另外,正如此处所述,您必须运行以下命令才能保存时区更改:

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


Md.*_*ain -1

根据php 文档,强烈建议您使用适合您所在位置的正确时区,例如Asia/ShanghaiAustralia/Perth不使用EETCET

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