把这个两个String转换为需要的时间出错?
一个是:2013.05.08 13:30:15
一个是:2013 05 14 14:17:25
因为都是String,所以我想先转换为Date,这样不对啊?
DateFormat format = new SimpleDateFormat("yyyy MM dd hh:mm:ss");
format.setLenient(false);
String s = "2013.05.08 13:30:15";
Timestamp ts = new Timestamp(format.parse(s).getTime());
System.out.println(ts.toString());
DateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss"); //这里修改了
format.setLenient(false);
String s = "2013.05.08 13:30:15";
Timestamp ts = new Timestamp(format.parse(s).getTime());
System.out.println(ts.toString());
String s = "2013.05.08 13:30:15";
DateFormat format = new SimpleDateFormat("yyyy.MM.dd hh:mm:ss");
Date date = null;
try {
date = format.parse(s);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(date.toString());
DateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
format.setLenient(false);
String s = "2013.05.08 13:30:15";
Timestamp ts = new Timestamp(format.parse(s).getTime());
System.out.println(ts.toString());
DateFormat format = new SimpleDateFormat("yyyy.MM.dd hh:mm:ss");
format.setLenient(false);
String s = "2013.05.08 01:30:15";
Timestamp ts = new Timestamp(format.parse(s).getTime());
System.out.println(ts.toString());