PHP time zone Setup Problem _php tutorial

Source: Internet
Author: User
After loading the PHP5 you will find this problem:

 
  

You may find that the output time is not the same as your current time.

The reason is that if you do not set your server local time zone in the program or configuration file, the time taken by PHP is Greenwich Mean time, so there will be a discrepancy with your local time.

Greenwich Mean Time and Beijing time is about 8 hours. So how do we avoid time errors?

Let's take a look at the workaround:

In the header, use Date_default_timezone_set () to set my default time zone to Beijing time.

 
  

The time is the same as the current time of the server.

Make sure that the H in date (' y-m-d h:i:s ') is uppercase if an Insert database error occurs.

Additional Date_default_timezone_set usage is as follows:

Date_default_timezone_set

(PHP 5 >= 5.1.0rc1)

Date_default_timezone_set--Set the default time zone for all datetime functions in a script

Description

BOOL Date_default_timezone_set (String timezone_identifier)

Date_default_timezone_set () Sets the default time zone for all datetime functions.

Note: Since PHP 5.1.0 (This version of the date time function is rewritten), each call to a DateTime function will produce an E_notice level error message if the time zone is not in law.

Parameters

Timezone_identifier

Time zone identifiers, such as UTC or Europe/lisbon

return value

This function always returns TRUE (even if the timezone_identifier argument is not valid).

or modify the Date.timezone value in php.ini, Date.timezone = PRC

http://www.bkjia.com/PHPjc/752579.html www.bkjia.com true http://www.bkjia.com/PHPjc/752579.html techarticle after loading the PHP5 you will find the question: Php$atime=date ("y-m-d h:i:s"); Echo $atime; > You may find that the output time is not the same as your current time. The reason is that if you ...

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