我有跟车问题。我将一个Carbon或DateTime对象保存在一个变量中。
$now = Carbon::now('Europe/Berlin');如果我第一次使用这个命令。一切都很好。但在one Day之后,它将返回在前一天生成的最后日期和时间。
例如:
此时正确的日期和时间应该是: 2018-12-14 13.48:00但是
dd($now);返回
Carbon @1544733487 {#555 ▼
date: 2018-12-13 21:38:07.319843 Europe/Berlin (+01:00)
}我正在使用Laravel 5.7,我已经在我的mac和我的共享主机提供商上进行了测试。
我不知道我做错了什么。如果你能帮我,我会很高兴的。
敬重基督徒
发布于 2018-12-14 21:01:01
这似乎是因为您的服务器的时区与您的不同。
这可能是由以下原因引起的:
Server misconfiguration
Physical location of the server is in a different timezone
Policies of your provider could also cause this. If your provider decides they want to operate on the same timezone on every server they have throughout the world, this will cause issues.服务器的时区似乎是CET (中欧时间),如您所述,这是+1 GMT。
要解决此问题,应在php.ini文件中更改时区(链接中提供了相关说明):
Open your php.ini file
Add the following line of code to top of your php.ini file:
date.timezone = "US/Central"或者,如果您希望PHP使用另一个时区,则应该将US/Central时区替换为此处列出的所需时区。
发布于 2018-12-14 21:37:18
在laravel上,打开您的config/app.php并查找"timezone“条目。在上面输入您自己的时区。
'timezone' => 'your_timezone_here'您可能还想运行
php artisan config:cache在改变之后。
https://stackoverflow.com/questions/53780252
复制相似问题