PHP date () function get time error solution

Source: Internet
Author: User
Tags current time echo date


After obtaining the time through the date () function, it is found that the hour time is incorrect, which is 8 hours less than the current time. Both H and h are the same, this is because the Greenwich Mean Time is obtained, which is 8 hours different from Beijing time.

The solution is as follows:
:
1. Modify the php. ini configuration file.

Open the php. Ini file. Generally, find the; date. timezone in the root directory of the php configuration. Delete the semicolon and change it to date timezone = PRC. Save and restart the Apahce service (sometimes there is a problem with restart, stop first and then start ).

2. Add the date_default_timezone_set (timezone_identifier) function
This function sets the current time zone, initializes the time, and adds this sentence before the page header or get the time statement.

For example:

Date_default_timezone_set (PRC );
Echo date ("Y-m-d H-I-s ");

The parameters are as follows:

Date_default_timezone_set (PRC)-set to Beijing time. PRC represents the People's Republic of China.
Date_default_timezone_set ('Asia/Shanghai')-set to Shanghai time. Available options include 'chungqi '(Chongqing) and 'Urumqi' (Urumqi).

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 (it seems that Beijing is not seen)

This function always returns True, but you must enter timezone_identifier. Otherwise, an error is returned.

The following are all the time zone identifiers: (for your reference)

CET

CST6CDT

Cuba

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

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.