MySQL java milliseconds 轉成 date , 或者 date 轉成 java milliseconds
1. 由 Date 轉換成 java milliseconds
Ex1:
SELECT UNIX_TIMESTAMP(CURDATE())*1000;
結果如下
+--------------------------------+
| UNIX_TIMESTAMP(CURDATE())*1000 |
+--------------------------------+
| 1417737600000 |
+--------------------------------+
1 row in set
Ex2
SELECT UNIX_TIMESTAMP(STR_TO_DATE('Apr 15 2012 12:00AM', '%M %d %Y %h:%i%p'))*1000;
+------------------------------------------------------------------------+
| UNIX_TIMESTAMP(STR_TO_DATE('Apr 15 2012 12:00AM', '%M %d %Y %h:%i%p'))*1000 |
+------------------------------------------------------------------------+
| 1334448000000 |
+------------------------------------------------------------------------+
1 row in set
2. 由 java milliseconds 轉換成 Date
先去以下網站 (java 日期轉換)取得 今天 2014-12-5 11:08 PM 的 milliseconds = 1417755600000
sql 如下
SELECT FROM_UNIXTIME( 1417755600000/1000, '%Y年%m月%d' ) ;
+---------------------------------------------------+
| FROM_UNIXTIME( 1417755600000/1000, '%Y年%m月%d' ) |
+---------------------------------------------------+
| 2014年12月05 |
+---------------------------------------------------+
1 row in set
Ex1:
SELECT UNIX_TIMESTAMP(CURDATE())*1000;
結果如下
+--------------------------------+
| UNIX_TIMESTAMP(CURDATE())*1000 |
+--------------------------------+
| 1417737600000 |
+--------------------------------+
1 row in set
Ex2
SELECT UNIX_TIMESTAMP(STR_TO_DATE('Apr 15 2012 12:00AM', '%M %d %Y %h:%i%p'))*1000;
+------------------------------------------------------------------------+
| UNIX_TIMESTAMP(STR_TO_DATE('Apr 15 2012 12:00AM', '%M %d %Y %h:%i%p'))*1000 |
+------------------------------------------------------------------------+
| 1334448000000 |
+------------------------------------------------------------------------+
1 row in set
2. 由 java milliseconds 轉換成 Date
先去以下網站 (java 日期轉換)取得 今天 2014-12-5 11:08 PM 的 milliseconds = 1417755600000
sql 如下
SELECT FROM_UNIXTIME( 1417755600000/1000, '%Y年%m月%d' ) ;
+---------------------------------------------------+
| FROM_UNIXTIME( 1417755600000/1000, '%Y年%m月%d' ) |
+---------------------------------------------------+
| 2014年12月05 |
+---------------------------------------------------+
1 row in set
留言
張貼留言