After installing PHP5, you will find the following problems:
<?php$atime=date("Y-m-d H:i:s");echo $atime;?>
You may find that the output time is different from the current time.
The reason is that if you do not set the local time zone of your server in the program or configuration file, the time taken by PHP is the Greenwich Mean Time, so it may be different from your local time.
The GMT standard time is about eight hours behind Beijing time. How can we avoid time errors?
Let's take a look at the solution:
Use date_default_timezone_set () in the header to set my default time zone to Beijing time.
<?date_default_timezone_set('PRC');echo date('Y-m-d H:i:s');?>
The time is the same as the current time of the server.
If a database insertion error occurs, make sure that H in date ('Y-m-d H: I: s') is in uppercase.
The usage of date_default_timezone_set is as follows:
Date_default_timezone_set
(PHP 5> = 5.1.0RC1)
Date_default_timezone_set -- set the default time zone used for all date and 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 datetime functions.
Note: Since PHP 5.1.0 (this version of the datetime function has been rewritten), if the time zone does not comply with the rules, every call to the datetime function will generate an E_NOTICE-level error message.
Parameters
Timezone_identifier
Time zone identifier, such as UTC or Europe/Lisbon
Return Value
This function always returns TRUE (even if the timezone_identifier parameter is invalid ).
Or modify the value of date. timezone in php. ini, date. timezone = PRC