Ask the problem that the conversion from a timestamp in php to a date is inconsistent with the conversion from a mysql function to a date.

Source: Internet
Author: User
Tags echo date
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.