Using PHP to set the system time zone

Source: Internet
Author: User
Tags time zones
partitioning of time zones

The world is divided into 24 time zones, each time zone has its own local time, the same time in the local time zone of 1-23 hours, such as the local time in London and Beijing local time difference of 8 hours. In the field of international radio communications, a uniform time is used, which is called Universal Coordinated Time (UTC), and UTC is the same as Greenwich Mean Time (GMT).

Time zone settings in PHP

Because PHP5 has rewritten the data () function. PHP defaults to the standard GMT (that is, the zero zone), so you must change the time zone setting for the PHP language to get the local current time.

There are two ways to change the time zone setting in the PHP language

(1) Modify the settings in the php.ini file to find [data]; date.timezone = option, remove the preceding quotation marks and modify to: Date.timezone = PRC (PRC is the Chinese People's Republic time zone), and then restart Apache.

(2) In the application, you need to add the following function before using the time-date function

Date_default_timezone_set (timezone);

Among them, the time-zones that can be used to set China's Beijing Times include PRC (Chinese name Republic), Asia/chongqing (Chongqing), Asia/shanghai (Shanghai) or Asia/urumqi (Urumqi)

List of legitimate time zones: http://www.php.net/manual/en/timezones.php

For example:

echo "UTC time:". Date ("Y-m-d h:i:s"). " <br> ";d ate_default_timezone_set (" PRC "), echo" Beijing time: ". Date (" Y-m-d h:i:s ")." <br> "; echo" Current time zone: ". Date_default_timezone_get ()." <br> ";

The result of the operation is:

UTC time: 2016-03-26 07:19:57
Beijing Time: 2016-03-26 15:19:57
Current time zone: 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.