CentOS 下安装 LEMP 服务(Nginx、MariaDB/MySQL 和PHP)(4)

How to set the default timezone in PHP

Question: How can I set the default timezone used by all date/time related PHP functions?

The default timezone for PHP is defined in php.ini configuration file. So you will need to edit the file by hand.

First, find the location of php.ini on your system as follows. In this example, it is found at /etc/php5/cli/php.ini.

$ php --ini
Configuration File (php.ini) Path: /etc/php5/cli
Loaded Configuration File:        /etc/php5/cli/php.ini
Scan for additional .ini files in: /etc/php5/cli/conf.d
Additional .ini files parsed:      /etc/php5/cli/conf.d/10-pdo.ini


Next, find out the timezone (TZ) string of your region. For that, you can use a command-line tool called tzselect. Simply run the following command:

$ tzselect


You will then go through interactive menu to identify your region.

How to set the default timezone in PHP

 

After you are done, tzselect will print the value of TZ variable as follows. In this example, the TZ value is "America/New York".

How to set the default timezone in PHP

 

Now open up php.ini in a text editor, and look up "date.timezone" variable in it. If "date.timezone" variable definition is commented out, uncomment the line. Then change the timezone accordingly. You are done!

date.timezone = "America/New_York"

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/9341e7218cbb3a6b1ec0b994ce96639a.html