PHP Time function errors and workarounds PHP date_default_timezone_set () function usage

Source: Internet
Author: User
Tags echo date what php
PHP Time function error and workaround PHP date_default_timezone_set () function usage

PHP Time function error and Workaround: PHP date_default_timezone_set () function Date.timezone time Zone These factors are affecting PHP time, the main problem is that the default PHP time function with Greenwich Mean Time and our time (Beijing time) difference is exactly 8 hours, this is the PHP time function error resolution of the population.

Previously encountered a problem, that is, echo date ("Y-m-d h:i:s", Time ()) back always with the actual time is not on, today finally found on the Internet, the reasons and solutions, share the following:

Starting from php5.1.0, PHP.ini added the Date.timezone time zone option, which by default is the display time (no matter what PHP command) is Greenwich Mean Time and our time (Beijing time) difference is exactly 8 hours, there are the following 3 methods can restore normal time.

1, the simplest way is not to use the version of php5.1 above

2, if must be used, and can not modify the php.ini, it is necessary in relation to the initialization of the time of the statement
Add Date_default_timezone_set (XXX) above;

3, once and for all, can only modify php.ini. Open php.ini Find Date.timezone time zone remove the preceding semicolon
= after adding xxx, restart the HTTP service (such as Apache2 or IIS, etc.). If php.ini can not find Date.timezone time zone This line, is not there is no way, of course, not, haha no words on their own add, self-clothed. I added such a sentence Date.timezone = "PRC", the problem is done, happy.

For XXX, the values available in mainland China are: asia/chongqing, Asia/shanghai, Asia/urumqi (Chongqing, Shanghai, Urumqi, respectively)
Taiwan available: Asia/macao, Asia/hong_kong, Asia/taipei (Macau, Hong Kong, Taipei, respectively)
and Singapore: Asia/singapore
The foreigner seems to have missed Beijing's tune.
Other available values are: Etc/gmt-8, Singapore, Hongkong, PRC
What is PRC? PRC is the People's Republic of China Ah-_-
———————————————————————————————————————
How to resolve:

Set my default time zone to GMT using the Date_default_timezone_set () function in the page header

Date_default_timezone_set (' PRC ');
echo Date (' y-m-d h:i:s ');

Time is the same as the current time of the server!! Congratulations on the
The attached date_default_timezone_set () function uses the following

——————————–
Date_default_timezone_set ()

(PHP 5 >= 5.1.0rc1)
Date_default_timezone_set () – Sets the default time zone for all datetime 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 date time function is rewritten), each call to a DateTime function will produce an E_notice level error message if the time zone is not in law.

Parameters

Timezone_identifier

Time zone identifiers, such as UTC or Europe/lisbon

return value
This function always returns TRUE (even if the timezone_identifier argument is not valid).

——————————————————————————————

Enclose the time zone identifier:

Cet
Cst6cdt
Cuba
The
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.