mysql数据库表中"created_time"字段的数据类型为bigint类型,其库中的数据为1164691264437,如何通过sql,将该类型的数据转换为datetime类型(如2006年11月28日 13:21)?曾尝试用convert、cast进行转换,结果均失败,正确的方法如下: |
-- 假设 1164691264437 是 Java 里的“日期时间”:即:自1970-01-01 00:00:00以来的毫秒数
/*
getTime
public long getTime()Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.
Returns:
the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this date.
*/
mysql> select from_unixtime(1164691264437/1000);
+-----------------------------------+
| from_unixtime(1164691264437/1000) |
+-----------------------------------+
| 2006-11-28 13:21:04 |
+-----------------------------------+
1 row in set (0.05 sec)