Php obtains the accurate current time of the system.

Source: Internet
Author: User
Php obtains the system's correct current time. incorrect php time zone. problem: date current time, time difference, local, local date_default_timezone_set1. The easiest way is not to use php5.1 or later version 2. if necessary, php cannot be modified. ini, you need to add date_default_timezone_set (XXX) to the statement about time initialization; 3, php gets the current time of the system correctly.

Incorrect php time zone time problem date current time, time difference, local, local date_default_timezone_set

1. the simplest method is not to use php5.1 or a later version.
2. if it must be used and php. ini cannot be modified, add date_default_timezone_set (XXX) to the time initialization statement );
3. only php. ini can be modified. Open php. ini and find date. timezone. remove the semicolon and add XXX. restart the http service (such as apache2 or iis ).

For XXX, the available values in mainland China are: Asia/Chongqing, Asia/Shanghai, Asia/Urumqi (Chongqing, Shanghai, and Urumqi in sequence)
Available in Hong Kong and Taiwan regions: Asia/Macao, Asia/Hong_Kong, Asia/Taipei (in the order of Macao, Hong Kong, and Taipei)
Singapore: Asia/Singapore
Other available values: Etc/GMT-8, Singapore, Hongkong, PRC (People's Republic of China)

Solution:
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!

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.