Php> problems related to php time zone time exceptions current time difference of date

Source: Internet
Author: User
Tags what php
Php & gt; php time zone time error question date current time difference (reproduced) about php time zone time error question date current time difference local date_default_timezone_set there is a legacy problem before, is echodate ("y-m-dh: I: s", time ()) the return time is always the same as the actual time. for the php time zone error, the current time difference of date (reprinted)

Php time zone time error problem date current time difference local date_default_timezone_set
There was a legacy problem, that is, echo date ("y-m-d h: I: s", time () is always not the same as the actual time, I finally found the cause and solution on the Internet today, and shared the following:
I will add that I will follow the instructions below to modify php. ini cannot find date. in timezone, is there no way to do this? of course not. if haha doesn't do it, add it by yourself. I added such a statement date. timezone = "PRC", and the problem was fixed. please be glad.
From php5.1.0, the date. timezone option is added to php. ini, which is disabled by default.

That is, the displayed time (no matter what php command is used) is the Greenwich Mean Time.

The difference between the time and our time (Beijing time) 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 );
Cp does not have this problem

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

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 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 !! Congratulations


The usage of date_default_timezone_set is as follows:

--------------------------------
Date_default_timezone_set

(PHP 5> = 5.1.0RC1)
Date_default_timezone_set -- set the default time zone used 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.