String转换为Timestamp

来源:互联网 发布:nginx cc攻击防御 编辑:程序博客网 时间:2024/05/20 09:08

两种方式将String类型的数据转换为Timestamp类型的数据

1. 使用Timestamp的valueOf()方法

String str = "2015-02-25 11:11:11";Timestamp t = Timestamp.valueOf(str);

2. 使用Timestamp的构造方法

SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");try {Date date = sf.parse(str);System.out.println(date);Timestamp t1 = new Timestamp(date.getTime());System.out.println(t1);} catch (ParseException e) {e.printStackTrace();}

0 0
原创粉丝点击