background image

DBFace.connect();

//清空表

String strDelete ="delete from time_table";
DBFace.update(strDelete);

//添加

 
String strInsert ="insert into time_table(CreateDateTime) values(20070409132013)";
DBFace.update(strInsert);

//获取

String strSelect ="select * from time_table";
ResultSet rsBuffer =DBFace.select(strSelect);

while

(rsBuffer.next())

{
Timestamp tsBuffer =rsBuffer.getTimestamp("CreateDateTime");
System.out.println(tsBuffer.toString());
}
DBFace.close();
}
 
执行结果: 2007-04-09 13:20:13.0
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 类型非常相似
范围为 1970-01-01 –2037 年,精度为 1 秒/
如果在 Sql 中未对 Timestamp 类型的列赋值,该列将被构造成当前时间。
提交 NULL 值也会使该列以当前时间录入。
如果时间提交错误,该列将被填入 0.
Timestamp 比 DateTime 类型所需的存储空间更小,只需要 4 个字节,而 DateTime 需要 8
个字节。
但是有一点需要特别注意。Timestamp 只能表示时间范围为 1970 -2037.
使用 Timestamp 一定要确保提交的时间数据一定不会超过这个范围。
代码与 DateTime 类是,而且我不喜欢用,所以略掉了。
Time:
A time. The range is '-838:59:59' to '838:59:59'. MySQL displays TIME values in 'HH:MM:SS' 
format, but allows you to assign values to TIME columns using either strings 

or

 numbers. 

 
Time 只记录时间信息,不包含日期信息。