mysql 中 unix_timestamp,from_unixtime 時間戳記函數

來源:互聯網
上載者:User

標籤:

1.unix_timestamp

將時間轉化為時間戳記。(date 類型資料轉換成 timestamp 形式整數)

沒傳時間參數則取目前時間的時間戳記

mysql> select unix_timestamp();
+------------------+
| unix_timestamp() |
+------------------+
|       1361586358 |
+------------------+
1 row in set (0.01 sec)

 

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)

 

2.from_unixtime

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

 

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)

mysql 中 unix_timestamp,from_unixtime 時間戳記函數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.