mysql bigint類型轉 於 datetime類型 互轉

  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. +-----------------------------------+      |

將Int 轉爲varchar經常用 concat函數,比如concat(8,'0') 得到字符串 '80'
2、將varchar 轉爲Int 用 cast(a as signed) a爲varchar類型的字符串
as  後 可跟參數:
二進制,同帶binary前綴的效果 : BINARY
字符型,可帶參數 : CHAR()
日期 : DATE
時間: TIME
日期時間型 : DATETIME
浮點數 : DECIMAL
整數 : SIGNED
無符號整數 : UNSIGNED


發佈了38 篇原創文章 · 獲贊 1 · 訪問量 27萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章