My classmates often ask me why the time of php time() and date() is different from that of the local computer. How many hours are there? If you calculate it carefully, there is a difference of 8 hours. This is a problem with the time zone setting of php date_default_timezone_set , we just need to set it up simply.
If the date time is inconsistent, you can use date_default_timezone_set to set the time zone:
The code is as follows
|
Copy code
|
||||
";
//Calculate the current time
echo date('Y-m-d H:i:s',time()-600); //Subtract 10 hours
echo " "; //Timestamp to time echo date('Y-m-d H:i:s',1364277600); //Convert time to timestamp (accurate to seconds only) echo strtotime("2013-03-26 14:00"); echo " ";
|
In addition to the above method, we can also set a time zone in php.ini, so that in the future there will be no need to add date_default_timezone_set('Asia/Chongqing'); in the program