转自:http://lbyzx123.iteye.com/blog/1073467
- 1、bigint类型转换为datetime类型
- -- 假设 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 |
- +-----------------------------------+
2、datetime类型转换为bigint类型
- -- 假设 "2011-05-31 23:59:59" 是 Java 里的“日期时间”:即:自1970-01-01 00:00:00以来的毫秒数
-
- mysql> select UNIX_TIMESTAMP('2011-05-31 23:59:59');
- +-----------------------------------+
- | from_unixtime(1306857599/1000) |
- +-----------------------------------+ |
本文介绍如何在MySQL中将bigint类型的数据转换为datetime类型,以及如何将datetime类型的数据转换为bigint类型。通过示例展示了如何使用from_unixtime和UNIX_TIMESTAMP函数实现毫秒级时间戳与日期时间字符串之间的相互转换。
1340

被折叠的 条评论
为什么被折叠?



