How to set the default time zone of php in mac

Source: Internet
Author: User
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 php55Installed php, but every time you run it date() strtotime()The system will report WarningPrompt 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 php55Installed php, but every time you run itdate() strtotime()The system will reportWarningPrompt 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.iniThe 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 usedbrewThe installed php (why should I install another php for mac), so you are not sure about the versionphp.iniWhere can I find it?

If not, run the command line

php -i | grep php.ini

Or createinfo.phpPage, and access the Code as follows:


  

FindConfiguration File (php.ini) PathIs 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");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.