MySQLÖÐDATETIMEºÍTIMESTAMPµÄÇø±ð

2015-07-24 08:32:20 ¡¤ ×÷Õß: ¡¤ ä¯ÀÀ: 1

ÏÈ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Ò»¶¨Òª×¢ÒâËûµÄʱ¼ä·¶Î§£¨¼ûÉÏ£©¡£