timestamp的有關問題

來源:互聯網
上載者:User
timestamp的問題
表結構:CREATE TABLE `id` (
`id` timestamp NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8

mysql> select * from id;
+---------------------+
| id |
+---------------------+
| 2013-01-10 20:21:04 |
+---------------------+
1 row in set (0.00 sec)

timestamp儲存的到底是時間戳記還是datetime類似格式的字串啊?
如果是時間戳記,為什麼select出來的不是時間戳記呢?
如果是datetime類似的字串,為什麼datetime 8位元組,而timestamp才四位元組?

謝謝各位指教.


------解決方案--------------------
MySQL中的datetime與timestamp比較

相同

顯示

TIMESTAMP列的顯示格式與DATETIME列相同。換句話說,顯示寬度固定在19字元,並且格式為YYYY-MM-DD HH:MM:SS。

不同

範圍

datetime 以'YYYY-MM-DD HH:MM:SS'格式檢索和顯示DATETIME值。支援的範圍為'1000-01-01 00:00:00'到'9999-12-31 23:59:59'TIMESTAMP值不能早於1970或晚於2037

儲存

TIMESTAMP

1.4個位元組儲存(Time stamp value is stored in 4 bytes)

2.值以UTC格式儲存( it stores the number of milliseconds)

3.時區轉化 ,儲存時對當前的時區進行轉換,檢索時再轉換回當前的時區。

datetime

1.8個位元組儲存(8 bytes storage)

2.實際格式儲存(Just stores what you have stored and retrieves the same thing which you have stored.)

3.與時區不轉換(It has nothing to deal with the TIMEZONE and Conversion.)

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.