【发布时间】:2018-08-15 21:00:16
【问题描述】:
我正在开发一个 Laravel 应用程序,它在 config/app.php 和 config/database.php 文件中将时区设置为 UTC,并且 MySQL 服务器上的时区设置为 America/丹佛,并且无法在此处更改,因为我们有多个应用程序使用该服务器。
问题是,在保存带有时间戳的新模型时,created_at/updated_at 设置在 America/Denver 时区,而我需要它们使用 UTC 时区。我玩了很多,但没有运气尝试了以下方法:
$ php artisan cache:clear
$ php artisan view:clear
$ php artisan config:cache
按照here 和here 的建议和here 的概述将我的PHP 脚本时区设置为UTC:
date_default_timezone_set('UTC')
按照建议 here 和概述的 here 将 MySQL 会话时区设置为 UTC:
DB::statement("SET time_zone='UTC';")
DB::select('SELECT @@global.time_zone, @@session.time_zone;')
我没有想法。任何建议都会很棒!
【问题讨论】:
标签: php mysql laravel datetime timezone