我已将时区配置config/app.php为Europe/Lisbon。
如果我执行 a return date_default_timezone_get();,它会Europe/Lisbon像我想要的那样返回。
到目前为止,一切都很好!
当我Carbon::now()这样做时,它返回例如 16 小时,而当前时间是 17 小时。有人可以解释为什么不考虑夏令时吗?
我正在使用 Laravel 7.16,PHP 7.4
问候
编辑1:代码图像+时间| https://i.stack.imgur.com/VMFVL.jpg
php artisan optimize:clear编辑2:当我更改配置中的某些内容时,总是会清除所有缓存。
编辑3:模型上的created_at和updated_at获得正确的时间。
编辑4:return Carbon::now()返回坏时间。这样做dd(Carbon::now())会返回正确的值,并在config/app.php|中配置时区。dd() 示例 ->date: 2020-07-08 17:25:28.935949 Europe/Lisbon (+01:00)
编辑5:在github上提出了一个问题 - https://github.com/laravel/framework/issues/33475
编辑6:就我而言,我使用 php date() 函数来解决该问题。不是我想要的方式,但完成了工作......
if (date(now()) > $subscriber->token_expire_date)
{
// return not found response
return $this->response(false, 410, 'The token has expired.', []);
}
Run Code Online (Sandbox Code Playgroud)