如何在 Laravel 中获取特定时区的时间?
How to get time in particular timezone in Laravel?
我无法使用 Laravel 8 获取特定时区的时间。我尝试了以下方法:
Carbon::now(new \DateTimeZone('Indian/Mauritius'))
我也试过修改文件config\app.php
中的timezone
如下:
'timezone' => 'Indian/Mauritius'
它总是返回我 UTC
时间。如何在特定时区使用 Carbon 获取时间?
编辑:问题已解决,问题是由于序列化问题,检查 here
这对我有用:
$dateNow = \Carbon\Carbon::now();
$dateNow->setTimezone('Indian/Mauritius');
我无法使用 Laravel 8 获取特定时区的时间。我尝试了以下方法:
Carbon::now(new \DateTimeZone('Indian/Mauritius'))
我也试过修改文件config\app.php
中的timezone
如下:
'timezone' => 'Indian/Mauritius'
它总是返回我 UTC
时间。如何在特定时区使用 Carbon 获取时间?
编辑:问题已解决,问题是由于序列化问题,检查 here
这对我有用:
$dateNow = \Carbon\Carbon::now();
$dateNow->setTimezone('Indian/Mauritius');