Today we have a very strange question:
The date information stored in the database is timestamp, the date information in the database is taken out in PHP and converted to "y-m-d" with the date () function , and the result is inconsistent with the MySQL Format function date_format () and is always less than one day.
This problem leads to hidden bugs in the program, it cost me a lot of effort, the last step of debugging, only to finally find that the date is inconsistent caused.
How to solve this problem?
Actually know the reason is good to do more, set a time zone is good, can be set in php.ini, inconvenient to modify the program can modify their own.
Date_default_timezone_set (' Asia/shanghai '); Set the default time zone to Shanghai
You can use the following function to print out the time zone information for the current environment:
Var_dump ' Asia/shanghai '
PHP Time Zone issues