Modify the default time zone for PHP

Source: Internet
Author: User
Tags echo date time zones local time

Each region has its own local time, in the Internet and radio communication, time conversion problem appears particularly prominent. The entire Earth is divided into 24 time zones, each with its own local time. In the case of international radio or network communications, for the sake of unification, a unified time is used to become a universal co-ordination (Universal time COORDINATED,UTC), which is the global standard times set by world standards. UTC was also originally a Greenwich mean Time (Greenwich Mean time,gmt), and was the same as the local time in London, UK.

The default time zone setting for PHP is UTC, and Beijing is located in the East eight zone of the time zone, leading UTC8 hours. So in the use of PHP time () and so on to get the current moment of the function, the resulting time is always wrong, performance and Beijing time difference of 8 hours.  If you want to display Beijing time correctly, you will need to modify the default time zone settings, which can be done in the following two ways. ① If you are using a standalone server with permissions to modify the configuration file, setting the time zone can be done by modifying the Date.timezone property in the php.ini. We can set the value of this property to one of "Asia/shang", "asia/chongqing", "etc/gmt-8" or PRC, and then the current time in the PHP script is Beijing time. Modify the PHP configuration file as follows: Date.timezone = etc/gmt-8//Set the default time zone in the configuration file to East 8 (Beijing time) ② if you are using a shared server, you do not have permission to modify the configuration file php.ini, and the ph The P version is again at 5.1.0 or more, and you can also call the Date_dafault_timezone_set () function to set the time zone before the output time. The function needs to provide a time zone identifier as a parameter, and the value of the Date.timezone property in the configuration file is the same.        The function is used as follows: Date_default_timezone_set (' PRC ');            The time zone that was set before the output times, PRC is the People's Republic of China Echo date (' y-m-d h:i:s '); The current time for the output is GMT

>> This article fixed link: http://php.ncong.com/php_course/date/morenshiqu.html

>> reprint Please specify: Ntshongwana PHP August 08, 2014 Yuncon PHP Learning tutorial Published

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.