Local time zone settings in php

Source: Internet
Author: User
Set the current output time in the local time zone of php: & lt ;? Php $ timedate (Y-m-dH: I: s); echo $ time; hour? How is it 2009-02-2606: 52: 58. The time of the local machine (Shanghai) is clearly: 2009-02-2614: 52: 58. I entered the next 8 hours in advance. :) You have already guessed that the UTC + 8 zone is a time zone problem, how does php know the local time zone settings in php?
Output Current time:
 

Why? 06:52:58. The local machine (Shanghai) time is clearly: 14:52:58
I entered the next 8 hours in advance. :) You have already guessed that the UTC + 8 zone is a time zone problem. how does php know the time zone? Modify the settings in php. ini:
[Date]; Defines the default timezone used by the date functionsdate.timezone = Asia/Shanghai

Restart the server and run the code again. The time output is consistent.

In php5, the default value of php. ini is GMT, and that of Beijing is + 8 time zone,
It is not recommended to modify the time zone settings in php. ini by using the php script. if you have a server with full management rights, you can also modify the default time zone settings in php. ini. If you do not have the permission to change php. ini,
You can use the ini_set () and date_default_timezone_set functions to set
  
Use echo date_default_timezone_get (); to view the settings.

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.