Changes to the default time zone for PHP

Source: Internet
Author: User
Tags echo date time zones local time
This article mainly introduces the PHP default time zone changes, has a certain reference value, now share to everyone, the need for friends can refer to

Each region has its own local time, and in the Internet and radio communication, time conversion problem is particularly prominent. The entire Earth is divided into 24 time zones, each with its own local time. In international radio or network communications, for the sake of unification, the use of a unified time, known as universal coordination (UTC,UNIVERSAL-time coordinated), is a global standard time set by the world-standard. UTC was also known as Greenwich Mean Time (Gmt,greenwich Mean times), which is the same as the local time in London, UK.

The default time zone setting for PHP is UTC, and Beijing is located in the East eight zone of the time zone, leading UTC eight hours. So when you use PHP like Time () and so on to get the current times of the function, the resulting time is always wrong, the performance is eight hours with Beijing time difference. If you want to display Beijing time correctly, you will need to modify the default time zone settings, which can be done in the following two ways.

If you are using a standalone server with permissions to modify the configuration file, setting the time zone can be done by modifying the Date.timezone property in PHP.ini. We can set the value of this property to one of "Asia/shang", "asia/chongqing", "etc/gmt-8" or PRC, and then the current time in the PHP script is Beijing time. The configuration file for modifying PHP is as follows:

Date.timezone = etc/gmt-8       //Set the default time zone in the config file to East 8 (Beijing time)

If you are using a shared server, you do not have permission to modify the configuration file php.ini, and the PHP version is at 5.1.0 or more, you can also call the Date_default_timezone_set () function to set the time zone before the output time. The function needs to provide a time zone identifier as a parameter, and the value of the Date.timezone property in the configuration file is the same. The use of this function is as follows:

Date_default_timezone_set (' PRC ');           Set time zone before output time, PRC for the People's Republic of China  Echo date (' y-m-d h:i:s ', Times ());         The current time for the output is GMT

Array unit returned by the GETDATE () function

Key Name

Description

Example of return value

Hours

Numeric representation of the hour

0~23

Mday

Numeric representation of the day of the month

1~31

Minutes

Numeric representation of minutes

0~59

Mon

Numeric representation of the month

1~12

Month

Full text representation of the month

January~december

Seconds

The numeric representation of the second

0~59

Wday

A numerical representation of the day of the week

0~6 (0 = Sunday)

Weekday

Full text representation of the day of the week

Sunday~saturday

Yday

The value shift of the day of the year

0~365

Year

4-bit representation of the year

Example: 1999 or 2009

0

The number of seconds since the Unix era began,

Similar to the return value of time () and the value used for date ()

System-dependent, typical values are from

-2147483648~2147483647

If you convert "October 1, 2009, 07:30:50 EDT" to Unix timestamp 1254382250, and pass it to the GETDATE () function, look at each array element as follows:

The value of Array (   [seconds] +                 //s =  [minutes] +//min = [  hours] = 7                    /h numeric representation  [Mday] + 1//month of the value of the                     day  [wday] = 4                     //The value of the day of the week  [mon] =                     //month of the  numeric representation [year ] =                  4 bits of the year//Years  [yday] = 273                   //year-on-day value offset  [weekday] = Thursday           //Full text representation of the day of the week  [Month] = October              //month Full text representation  [0] = 1254382250               //number of seconds since the beginning of the Unix era  )

The above is the whole content of this article, thank you for reading.

Related Article

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.