先Copy一份文檔給大家看:
DateTime
A date and time combination. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'.
MySQL displays DATETIME values in 'YYYY-MM-DD HH:MM:SS' format, but allows you to assign values to DATETIME columns using either strings or numbers.
TimeStamp
A timestamp. The range is '1970-01-01 00:00:00' to partway through the year 2037.
A TIMESTAMP column is useful for recording the date and time of an INSERT or UPDATE operation.
The first TIMESTAMP column in a table is automatically set to the date and time of the most recent operation if you don't assign it a value yourself.
You can also set any TIMESTAMP column to the current date and time by assigning it a NULL value.
DATETIME,字節數為8,取值范圍為“1000-01-01 00:00:00——9999-12-31 23:59:59”
對應Java類型為java.sql.Timestamp
INSERT或UPDATE操作時系統不會自動修改其值,不可以設定默認值,為必須字段時必須手動插入,建議使用:new()
MySql按照YYYY-MM-DD HH:MM:SS對數據進行格式化,允許以字符串和數字的方式提交
eg:insert into time_table(CreateDate) values(‘2014-06-09 15:01:01’)
或insert into time_table(CreateDate) values(‘20140609150101’)
TIMESTAMP,字節數為4,取值范圍為“19700101080001——20380119111407”
對應Java類型為java.sql.Timestamp
INSERT或UPDATE操作時(且未手動賦值)系統會自動更新、插入當前系統時間,默認值為CURRENT_TIMESTAMP()
提交手動賦值為NULL時也會被賦值為當前系統時間,錯誤時會填入0
使用TIMESTAMP一定要注意他的時間范圍(見上)。