PHP System time zone 8-hour Difference setting method _php Tutorial

Source: Internet
Author: User
Tags echo date
PHP Tutorial System time zone 8-hour difference setting method
There are two ways to modify the PHP system time zone:
1. Modify the settings in the php.ini file, locate ";d ate.timezone=" under [Date], modify the entry to Date.timezone=asia/hong_kong (PRC time in China), and then restart the Apache server.

2. In the application, add the "Date_default_timezone_set (" Asia/hong_kong ") function before using the time-date function

To get local time after modifying the php.ini file:
PHP Code:
echo "is now Beijing time:". Date ("Y-m-d h:i:s"). "

”;
?>
Show Results:
It's Beijing time: 2010-11-30 20:50:03 (in accordance with local time)
PHP.ini the modified code:
[Date]
; Defines the default timezone used by the date functions
; Http://php.net/date.timezone
Date.timezone = PRC

Here's a look at more ways

1. Modify the settings in the php.ini file.
[Date]
Defines the default timezone used by the date functions
Date.timezone = Asia/shanghai
It's really ... You can set Shanghai,chongqin,hong_kong,taibei ... Wait, but just did not find Beijing, do not know what is the reason.

2. Run-time settings in the PHP program.
if (Date_default_timezone_get ()! = "1asia/shanghai") Date_default_timezone_set ("Asia/shanghai");
?>
Note: There is a 1 in the time settings obtained with "Date_default_timezone_get", and it is not clear that it is a miscellaneous matter.

3. In the use of time, the extra 8*3600 second is also a drop.
echo Date ("Y-m-d h:i:s", Time () +8*3600);
?>

Note:
Starting with php5.0, it takes 8 hours less time to get the system time in PHP than the current time. The reason is that PHP is used UTC time when TimeZone is not set in php.ini, so the time in China is less than 8 hours

http://www.bkjia.com/PHPjc/632304.html www.bkjia.com true http://www.bkjia.com/PHPjc/632304.html techarticle PHP Tutorial System time zone 8-hour difference setting method to modify the PHP system time zone two ways: 1, modify the settings in the php.ini file, find [Date], date.timezone=, change the item to date ...

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