【问题标题】:Wrong timezone UTC in laravel 5.0?laravel 5.0 中的时区 UTC 错误?
【发布时间】:2016-04-15 09:46:56
【问题描述】:

我在config/app.php 中设置了'timezone' => 'UTC',

并使用此网络:UTC online 查看当前时间。

然后我在数据库中创建一行,时间为:

但是在我的数据库中创建的行,created_atupdated_at(时间戳)列的值是:2016-01-11 06:25:11(错误的秒数)。

任何帮助。谢谢!

【问题讨论】:

标签: php mysql laravel-5 timezone timestamp


【解决方案1】:

在你的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.
|
*/

'timezone' => 'UTC',

您可以简单地替换任何 PHP 支持的时区,而不是 UTC。例如,我开发过的一些应用程序有 Australia/Sydney 以将所有时间都本地化,即使在夏令时也是如此。

如果你真的想要,你可以继续在你的应用启动中的某个地方调用date_default_timezone_set(),但这是完全内置在 Laravel 中的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-15
    • 2015-12-17
    • 2016-07-22
    • 2015-05-09
    • 2014-11-08
    • 1970-01-01
    • 2016-04-02
    • 2021-03-18
    相关资源
    最近更新 更多