Timestamp 可以精确到小数秒 一般存储的格式:2002-01-29 04:33:38.531
Timestamp 可以获取当前时间,也可以把字符串装换成Timestamp类型
前期准备工作(包括相关工具或所使用的原料等)
windos7 或 windows xp
eclipse
详细的操作方法或具体步骤
获取当前时间:
第一种:
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);

- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
