Summary of setting time zone methods in PHP

Source: Internet
Author: User

Method One, set the time zone on the PHP page

In the front of the page plus the following application is OK

Date_default_timezone_set usage is as follows
Date_default_timezone_set
(PHP 5 >= 5.1.0rc1)
Date_default_timezone_set--Sets the default time zone for all date-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 date-time functions.


Usage

  code is as follows copy code

1 Date_ Default_timezone_set (' Asia/shanghai ');//' Asia/shanghai '    Asia/Shanghai

2 Date_default_timezone_set (' Asia/chongqing '), where asia/chongqing ' is "Asia/Chongqing"

3 date_default_timezone_set (' PRC '), where PRC is "People's Republic of China"

4 Ini_set (' Date.timezone ', ' etc/gmt-8 ');

5 ini_set (' Date.timezone ', ' PRC ');

6 ini_set (' Date.timezone ', ' Asia/shanghai ');

7 ini_set (' Date.timezone ', ' asia/chongqing ');

asia/shanghai– Shanghai
asia/chongqing– Chongqing
asia/urumqi– Urumqi
asia/hong_kong– Hong Kong
asia/macao– Macau
asia/taipei– Taipei
asia/singapore– Singapore


If you have server admin privileges, we can set the time zone in php.ini

The code is as follows Copy Code

Date.timezone = PRC

Remove the front semicolon and restart Apache

Some of the problems you might encounter

1.warning:strftime (): It isn't safe to rely on the system's timezone settings. You are are *required* to use the Date.timezone setting or the Date_default_timezone_set () function.

2.warning:date (): It isn't safe to rely on the system's timezone settings. You are are *required* to use the Date.timezone setting or the Date_default_timezone_set () function.

3.notice:date_default_timezone_set (): TimeZone ID ' Asia/shanghai ' is invalid

Solutions

The code is as follows Copy Code

Date_default_timezone_set (' Asia/shanghai ');//' Asia/shanghai ' Asia/Shanghai

Date_default_timezone_set (' asia/chongqing '), where asia/chongqing ' is "Asia/Chongqing"

Date_default_timezone_set (' PRC '), in which PRC is the "People's Republic of China"

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.