问题描述
我刚开始使用Carbon扩展名(到目前为止似乎很不错),但是对Carbon::now()
函数感到困惑.根据文档,似乎该功能应该反映用户当前时区中的当前时间,但是,我似乎比GMT早了一个小时.
I just started using the Carbon extension (seems pretty sweet so far), but am confused on the Carbon::now()
function. According to the docs, it seems as though this function should reflect the current time in the users current timezone, however, I seem to get a time that is an hour ahead of GMT.
即当我在PST上且实际上当前是2015-01-01 08:26:46
时,Carbon::now()
说2015-01-01 17:26:46
.
i.e. Carbon::now()
says 2015-01-01 17:26:46
when I am on PST and it is actually currently 2015-01-01 08:26:46
.
我是否必须为所有实例检测并放入用户本地时区?
Do I have to detect and put in a users local timezone for all instances?
有什么作用? (我很可能会对网站如何获取用户本地时间产生根本性的误解)
What gives? (I very well may have a fundamental misunderstanding of how a website gets a users local time)
推荐答案
这似乎是因为服务器的时区与您自己的时区不同.
This appears to be because the timezone of your server is different to your own.
这可能是由于:
- 服务器配置错误
- 服务器的物理位置在不同的时区
- 您提供者的政策也可能导致此情况.如果您的提供商决定他们希望在全球范围内的每台服务器上都在相同的时区进行操作,这将引起问题.
服务器的时区似乎是CET(欧洲中部时间),即您所描述的+1 GMT.
The server's timezone appears to be CET (Central European Time) which is +1 GMT, as you described.
要解决此问题,您应该更改php.ini
文件中的时区(说明来自链接):
To fix this, you should change the timezone in your php.ini
file (instructions are from the link):
- 打开您的
php.ini
文件 - 将以下代码行添加到php.ini文件的顶部:
或者,您应该将US/Central
时区替换为所需的时区此处概述如果您希望PHP使用其他时区.
Alternatively you should replace the US/Central
timezone with the desired timezone as outlined here if you wish PHP to use another timezone.
这篇关于碳现在时间错了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!