mysql bigint型別和datetime型別的轉換

lzq0107發表於2020-04-07
  1. 1、bigint型別轉換為datetime型別
  2. -- 假設 1164691264437 是 Java 裡的“日期時間”:即:自1970-01-01 00:00:00以來的毫秒數
  3. /*
  4. getTime
  5. public long getTime()Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.

  6. Returns:
  7. the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this date.
  8. */
  9. mysql> select from_unixtime(1164691264437/1000);
  10. +-----------------------------------+
  11. | from_unixtime(1164691264437/1000) |
  12. +-----------------------------------+
  13. | 2006-11-28 13:21:04               |
  14. +-----------------------------------+

         2、datetime型別轉換為bigint型別

  1. -- 假設 "2011-05-31 23:59:59" 是 Java 裡的“日期時間”:即:自1970-01-01 00:00:00以來的毫秒數

  2. mysql> select UNIX_TIMESTAMP('2011-05-31 23:59:59');
  3. +-----------------------------------+
  4. | from_unixtime(1306857599/1000) |
  5. +-----------------------------------+      |

相關文章