PHP设置时区的几种方法

WBOY
Release: 2016-06-20 13:02:40
Original
1730 people have browsed it

php程序的时区设置是web服务器安装的时候应该设置好的,但是如果你把网站放到国外的话,一般环境默认的是当地的时区,而你网站内容需要显示的是我们国内的时区,这时候就应该修改设置下时区了,下面介绍几种PHP设置时区的几种方法:

1、修改PHP.ini设置时区

在php.ini文件中找到date.timezone这行,去掉前面的分号,改成: 

date.timezone = Asia/Shanghai
Copy after login

2、修改 .htaccess文件设置时区

修改.htaccess文件有两种办法,下面的两条语句只要有一条即可

<p>php_value date.timezone Asia/Shanghai</p><p>SetEnv TZ Asia/Shanghai </p>
Copy after login

3、修改PHP代码设置时区

也是下面的两条语句只要其中的一句即可

<p>date_default_timezone_set(‘Asia/Shanghai’);</p><p>ini_set(‘date.timezone’,'Asia/Shanghai’); </p>
Copy after login

通过上面的设置修改,一般就可以设定会我们国内的时区,显示正确的时间了。


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!