Time zone in the date function in PHP

Source: Internet
Author: User

PHP users may have encountered this situation. Date ("Y-m-d h: I: s") Total server time differences

Hours. I checked it online to find out. Originally, from php5.1.0, the date. timezone option was added to PhP. ini.

Is disabled by default, that is, the display time (no matter what php Command is used) is the Greenwich Mean

Accurate Time, so this happens,

The solution is as follows:
1. Use date_default_timezone_set () in the page header to set my default time zone to Beijing Time
Date_default_timezone_set ('prc ');
Echo date ('Y-m-d h: I: s ');
The time is the same as the current server time !!

2. Modify PHP. ini.
Open php5.ini to search for date. timezone. Remove the semicolon = followed by XXX and restart the HTTP service.

(Such as apache2 or IIS.
For XXX, the available values in mainland China are: Asia/Chongqing, Asia/Shanghai,

Asia/Urumqi (in the order of Chongqing, Shanghai, Urumqi) Hong Kong and Taiwan regions available: Asia/Macao,

Asia/hong_kong, Asia/Taipei (in the order of Macao, Hong Kong, and Taipei) and Singapore:

Asia/Singapore foreigners seem to have missed other available values in Beijing: ETC/GMT-8, Singapore,

What Is Hongkong, PRC, and PRC? PRC is from the People's Republic of China.

The area below GMT + 8 may be omitted.

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.