The MySQL database has a table infor, under which there is a field in time and the type is int (10), and there is a data bit under the field: 1383346800
Here's the problem:
I use the PHP function echo date ("Y-m-d h:i:s", 1383346800); The operation result is: 2013-11-01 23:00:00
And with the MySQL function select From_unixtime (1383346800); The operation result is: 2013-11-02 07:00:00
Why the same timestamp PHP and MySQL are two results? Which is the right result? Ask the elder to look under, both methods I need, because I want to use these two methods to compare the results, can let two kinds of results consistent, or is not it? Thank goodness people for helping me!
Reply to discussion (solution)
Two are right, there's nothing wrong!
It's just a different point of reference.
For 1383346800 there are
Beijing Time 2013-11-02 07:00:00
GMT 2013-11-01 23:00:00
Just one East eight, 8 hours.
Time zone problem, your PHP reference is Greenwich Mean time, and local time difference of 8 hours.
Date_default_timezone_set (' PRC ') sets the value in the time zone or php.ini to change DATE.TIMEZONE=PRC.
1 date_default_timezone_set (' Asia/shanghai ');//' Asia/shanghai ' Asia/Shanghai
2 Date_default_timezone_set (' asia/chongqing ');//Where asia/chongqing ' is ' Asia/Chongqing '
3 Date_default_timezone_set (' PRC ');//Where PRC is the "People's Republic of China"
Http://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html
Set the time zone before you get it, OK
Http://www.w3school.com.cn/php/php_ref_date.asp
Here's a good introduction: the behavior of the date/time function is affected by the settings in php.ini.
Then there are two ways to solve the problem, as the 2 floor says.