Php time function error and solution: phpdate_default_timezone_set () function usage

Source: Internet
Author: User
Tags what php
Php time function error and solution phpdate_default_timezone_set () function usage php time function error and solution: phpdate_default_timezone_set () function date. timezone Time Zone these factors affect the php time. The main problem is the error and solution of the default php time function php date_default_timezone_set () function usage.

Php time function error and solution: php date_default_timezone_set () function date. timezone Time Zone these factors affect php time. The main problem is that the default php time function uses Greenwich mean time and our time (Beijing time), which is exactly eight hours different, this is also the population of php time function error solutions.

A problem encountered previously was that the return time of echo date ("y-m-d h: I: s", time () was always not the same as the actual time, I finally found the cause and solution on the Internet today, and shared the following:

Php. date is added to ini. the timezone option is disabled by default, that is, the displayed time (no matter what php command is used) is the Greenwich mean time and our time (Beijing time) the difference is exactly 8 hours. in the following three ways, we can restore the normal time.

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 );

3. once and for all, only php. ini can be modified. Open php. ini and find date. timezone. remove the semicolon
= Add XXX to the backend and restart the http service (such as apache2 or iis. If php. ini cannot find the date. timezone time zone, isn't it possible? no, of course not. if haha doesn't, add it by yourself. I added such a statement date. timezone = "PRC", and the problem was solved.

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
Foreigners seem to have missed Beijing
Other available values are: Etc/GMT-8, Singapore, Hongkong, PRC
What is PRC? PRC is the People's Republic of China -_-
---------------------------------------
Solution:

Use the date_default_timezone_set () function 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 !! Congratulations
The usage of the date_default_timezone_set () function is as follows:

-----------
Date_default_timezone_set ()

(PHP 5> = 5.1.0RC1)
Date_default_timezone_set ()-sets the default time zone for all date and time functions in a script.
Description
Bool date_default_timezone_set (string timezone_identifier)

Date_default_timezone_set () sets the default time zone for all datetime functions.

Note: Since PHP 5.1.0 (this version of the DATETIME function has been rewritten), if the time zone does not comply with the rules, every call to the DATETIME function will generate an E_NOTICE-level error message.

Parameters

Timezone_identifier

Time zone identifier, such as UTC or Europe/Lisbon

Return value
This function always returns TRUE (even if the timezone_identifier parameter is invalid ).

------------------------------

Attach the time zone identifier:

CET
CST6CDT
EET
Egypt
Eire
EST
EST5EDT
Etc/GMT
Etc/GMT + 0
Etc/GMT + 1
Etc/GMT + 10
Etc/GMT + 11
Etc/GMT + 12
Etc/GMT + 2
Etc/GMT + 3
Etc/GMT + 4
Etc/GMT + 5
Etc/GMT + 6
Etc/GMT + 7
Etc/GMT + 8
Etc/GMT + 9
Etc/GMT-0
Etc/GMT-1
Etc/GMT-10
Etc/GMT-11
Etc/GMT-12
Etc/GMT-13
Etc/GMT-14
Etc/GMT-2
Etc/GMT-3
Etc/GMT-4
Etc/GMT-5
Etc/GMT-6
Etc/GMT-7
Etc/GMT-8
Etc/GMT-9
Etc/GMT0
Etc/Greenwich
Etc/UCT
Etc/Universal
Etc/UTC
Etc/Zulu
Factory
GB
GB-Eire
GMT
GMT + 0
GMT-0
GMT0
Greenwich
Hongkong
HST
Iceland
Iran
Israel
Jamaica
Japan
Kwajalein
Libya
MET
MST
MST7MDT
Navajo
NZ
NZ-CHAT
Poland
Portugal
PRC
PST8PDT
ROC
ROK
Singapore
Turkey
UCT
Universal
UTC
W-SU
WET

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.