java.sql.Timestamp 类的使用
的有关信息介绍如下:Timestamp 可以精确到小数秒 一般存储的格式:2002-01-29 04:33:38.531
Timestamp 可以获取当前时间,也可以把字符串装换成Timestamp类型
获取当前时间:
第一种:
Timestamp nowdate1 = new Timestamp(System.currentTimeMillis());
System.out.println("System.currentTimeMillis():"+nowdate1);
第二种:
Date date = new Date();
Timestamp nowdate2 = new Timestamp(date.getTime());
System.out.println("new Date():"+nowdate2)
把String类型转换Timestamp:
String datestr = "2002-01-29 04:37:21.453";
Timestamp ts = Timestamp.valueOf(datestr);
System.out.println(ts);
把Timestamp 类型转换String:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Timestamp nowdate = new Timestamp(System.currentTimeMillis());
String datestr = sdf.format(nowdate);
System.out.println(datestr);