Ask the problem that the previous timestamp is converted into a date using php and converted into a date using mysql function. mysql database has a table named "infor", which has a field "time, type: int (10). This field has a data bit: 1383346800
Question:
I used the php function echo date ("Y-m-d H: I: s", 1383346800). The running result is 23:00:00.
The mysql function select from_unixtime (1383346800) is used. the running result is 07:00:00.
Why is the same timestamp of php and mysql two results? Which result is correct? Please help me to see if I need both methods, because I want to compare the results using these two methods, can the two results be consistent, or can't I? Thank you for helping me!
Reply to discussion (solution)
Neither of them is correct!
It's just a reference point.
For 1383346800
07:00:00 Beijing time
23:00:00 GMT
The difference is 8 hours in the UTC + 8 zone.
For time zone problems, your php reference Greenwich Mean Time, which is 8 hours different from the local time.
Date_default_timezone_set ('prc') to change the value of date. timezone = PRC in the time zone or php. ini.
1 date_default_timezone_set ('Asia/Shanghai'); // 'Asia/Shanghai' Asia/Shanghai
2 date_default_timezone_set ('Asia/Chongqing '); // The value of Asia/Chongqing is "Asia/Chongqing"
3 date_default_timezone_set ('prc'); // PRC is "People's Republic of China"
Http://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html
Set the time zone before obtaining the time.
Http://www.w3school.com.cn/php/php_ref_date.asp
Here is a good introduction: the behavior of date/time functions is affected by the settings in php. ini.
There are two solutions as mentioned on the second floor.