如何更改apache服务器中的时间以使其与计算机的时间(PHP)相匹配?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8648369/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change the time in apache server so it matches the computer's time (PHP)?
提问by menislici
In my particular case, both the server and the client are the same computer, I'm on localhost. When i echo out the date from the date() function, it displays a totally wrong value, a 11 hours earlier time. I also tried gmdate(), but it displays the date in AM not PM. Is there any way to change the apache server time, so everytime I get it in php, it displays the same as the time on my computer?
在我的特殊情况下,服务器和客户端都是同一台计算机,我在本地主机上。当我从 date() 函数中回显日期时,它显示了一个完全错误的值,早了 11 小时。我也试过 gmdate(),但它显示的是上午而不是下午的日期。有什么办法可以改变apache服务器的时间,所以每次我在php中得到它时,它显示的时间和我电脑上的时间一样吗?
EDIT: Sorry for the late edit. I have already set the timezone in the php.ini but it still doesn't work. And I'm sure that my timezone is correct, since I got it from the manual and checked from phpinfo().
编辑:抱歉编辑晚了。我已经在 php.ini 中设置了时区,但它仍然不起作用。而且我确定我的时区是正确的,因为我从手册中得到它并从 phpinfo() 中检查。
采纳答案by Andy Baird
回答by Franz Holzinger
Open the php.ini under /etc/php.ini .
打开 /etc/php.ini 下的 php.ini 。
Uncomment this line and add your continent and the main city. Here is an example which works for Germany (Deutschland).
取消注释此行并添加您的大陆和主要城市。这是一个适用于德国(德国)的示例。
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Europe/Berlin
See the website http://php.net/manual/de/timezones.phpfor all timezones in German.
有关德语的所有时区,请参阅网站http://php.net/manual/de/timezones.php。
Save the file php.ini. And restart the apache. Mageia LINUX uses this:
保存文件 php.ini。并重新启动apache。Mageia LINUX 使用这个:
systemctl restart httpd.service
回答by Justin
You need to do this in your php.ini file. I am on windows and run WAMP so my php.ini location is at: c:/wamp/bin/apache/Apache2.2.21/bin/
您需要在 php.ini 文件中执行此操作。我在 Windows 上运行 WAMP,所以我的 php.ini 位置在:c:/wamp/bin/apache/Apache2.2.21/bin/
You then open that file and the default is set to: date.timezone = UTC
You would change this value for whatever timezone you want...
然后打开该文件并将默认值设置为:date.timezone = UTC
您可以为所需的任何时区更改此值...
For a full list of timezones supported, you can visit: http://php.net/manual/en/timezones.php
有关支持的时区的完整列表,您可以访问:http: //php.net/manual/en/timezones.php
回答by Njoroge Mathu
This can be changed in the php.ini
:
这可以在php.ini
:
- If using xampp, open
xampp/php/php.ini
. - Look for the line
date.timezone=Europe/Berlin
and change it to your timezone.
In my case I changed todate.timezone=Africa/Nairobi
. - Save and restart apache.
- 如果使用 xampp,请打开
xampp/php/php.ini
. - 查找该行
date.timezone=Europe/Berlin
并将其更改为您的时区。
就我而言,我改为date.timezone=Africa/Nairobi
. - 保存并重启apache。