New to mac, I installed php through brewinstallphp55, but every time I run a function related to date () strtotime (), the system will report a Warning prompt asking me to set the time zone, so where can I modify the php configuration file and change the default time zone of php? For mac beginners, I use
brew install php55
Installed php, but every time you run it
date() strtotime()
The system will report
Warning
Prompt me to set the time zone. Where can I modify the php configuration file and change the default time zone of php?
Reply content:
For mac beginners, I usebrew install php55
Installed php, but every time you run itdate() strtotime()
The system will reportWarning
Prompt me to set the time zone. Where can I modify the php configuration file and change the default time zone of php?
You must set your own time zone after php5, either modify the settings of php. ini, or modify them in the code.
Set the time zone in PHP. INI
date.timezone = PRC
For php installed via brew in Mac, the ini is located:
/Usr/local/etc/php/5.6/php. ini
The position of the php5.5. * version ini is
/Usr/local/etc/php/5.5/php. ini
Set the time zone in the code
Date_default_timezone_set ('Asia/Shanghai'); // 'Asia/Shanghai' Asia/Shanghai date_default_timezone_set ('Asia/Chongqing '); // Asia/Chongqing is "Asia/Chongqing" date_default_timezone_set ('prc'); // PRC is "People's Republic of China" ini_set ('date. timezone ', 'etc/GMT-8'); ini_set ('date. timezone ', 'prc'); ini_set ('date. timezone ', 'Asia/Shanghai'); ini_set ('date. timezone ', 'Asia/Chongqing ');
Any of the above seven methods can meet our needs.
When the system is initialized, add
ini_set('date.timezone','Asia/Shanghai');
Or
date_default_timezone_set("PRC");
This will solve the problem that the time zone is 8 hours different.
Generally, the php configuration file is namedphp.ini
The default path is/etc/php.ini
(Default path for mac built-in php) or/etc/php5/php.ini
(* Nix default path). The path varies depending on the operating system and the installation method.
I have never usedbrew
The installed php (why should I install another php for mac), so you are not sure about the versionphp.ini
Where can I find it?
If not, run the command line
php -i | grep php.ini
Or createinfo.php
Page, and access the Code as follows:
FindConfiguration File (php.ini) Path
Is the path of php. ini.
Time Zone setting example
date.timezone=Aisa/Shanghai
Detailed description http://php.net/date.timezone
date_default_timezone_set("PRC");