java.sql.Timestamp 类的使用

2025-05-16 17:43:51

1、获取当前时间:第一种:Timestamp now蟠校盯昂date1 = 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)

java.sql.Timestamp 类的使用

2、把String类型转换Timestamp:String datestr = "2002-01-29 04:37:21.453";Timestamp ts = Timestamp.valueOf(datestr);System.out.println(ts);

java.sql.Timestamp 类的使用

3、把Timestamp 类型转换String:SimpleDateFormat sdf = new Simpl髫潋啜缅eDateFormat("yyyy-MM-dd HH:mm:ss");Timestamp nowdate = new Timestamp(System.currentTimeMillis());String datestr = sdf.format(nowdate);System.out.println(datestr);

java.sql.Timestamp 类的使用
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢