How to convert timestamp to datetime in MySQL?
如何转换1300464000
至2011-03-18 16:00:00
在MySQL?
Use the FROM_UNIXTIME()
function in MySQL
Remember that if you are using a framework that stores it in milliseconds (for example Java's timestamp) you have to divide by 1000 to obtain the right Unix time in seconds.
DATE_FORMAT(FROM_UNIXTIME(`orderdate`), '%d-%m-%Y') as "Date" FROM `orders`
如果给定日期采用编码格式,如1300464000
则这是最终的解决方案
To answer Janus Troelsen comment
Use UNIX_TIMESTAMP instead of TIMESTAMP
SELECT from_unixtime( UNIX_TIMESTAMP( "2011-12-01 22:01:23.048" ) )
The TIMESTAMP function returns a Date or a DateTime and not a timestamp, while UNIX_TIMESTAMP returns a unix timestamp
链接地址: http://www.djcxy.com/p/25058.html