【发布时间】:2021-09-22 10:34:40
【问题描述】:
我无法使用 Laravel 8 获取特定时区的时间。我尝试了以下方法:
Carbon::now(new \DateTimeZone('Indian/Mauritius'))
我也试过修改文件config\app.php中的timezone如下:
'timezone' => 'Indian/Mauritius'
它总是返回UTC 时间。如何在特定时区使用 Carbon 获取时间?
编辑:问题已解决,问题是由于序列化问题,检查here
【问题讨论】:
-
更新config\app.php后运行这些命令, --> php artisan config:cache -->php artisan cache:clear
-
你试过这个 Carbon::now()->timezone("Indian/Mauritius"); 吗?或如 PSA 建议的那样
-
@PSA,我试过了,不行
-
@JohnLobo,不,它不起作用。我在毛里求斯 15:15 收到
"2021-07-13T11:14:39.845698Z" -
您是否尝试在 AppServiceProvider 的启动方法中设置
date_default_timezone_set('Indian/Mauritius');?
标签: laravel laravel-8 php-carbon