1.unix_timestampmysql
將時間轉化爲時間戳。(date 類型數據轉換成 timestamp 形式整數)sql
沒傳時間參數則取當前時間的時間戳unix
mysql> select unix_timestamp();
+------------------+
| unix_timestamp() |
+------------------+
| 1361586358 |
+------------------+
1 row in set (0.01 sec)date
mysql> select unix_timestamp('2013-01-01 10:10:10');
+---------------------------------------+
| unix_timestamp('2013-01-01 10:10:10') |
+---------------------------------------+
| 1357006210 |
+---------------------------------------+
1 row in set (0.00 sec)select
2.from_unixtimeim
將timestamp 形式整數 轉化爲 date類型時間戳
mysql> select from_unixtime(1355272360);
+---------------------------+
| from_unixtime(1355272360) |
+---------------------------+
| 2012-12-12 08:32:40 |
+---------------------------+
1 row in set (0.00 sec)數據
固然也能夠指定輸出的時間格式:時間
mysql> select from_unixtime(1355272360,'%Y%m%d');
+------------------------------------+
| from_unixtime(1355272360,'%Y%m%d') |
+------------------------------------+
| 20121212 |
+------------------------------------+360
3.關於mysql 時間戳的限制
目前timestamp 所能表示的範圍在 1970 - 2038之間 。
超過這個範圍 獲得的時間將會溢出 獲得的時間是null.
mysql> select from_unixtime(0);
+---------------------+
| from_unixtime(0) |
+---------------------+
| 1970-01-01 08:00:00 |
+---------------------+
mysql> select from_unixtime(2147483647);+---------------------------+| from_unixtime(2147483647) |+---------------------------+| 2038-01-19 11:14:07 |+---------------------------+1 row in set (0.00 sec)