String datevalue="2006-10-10 20:22:10.0";
SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date d=formater.parse(datevalue);
System.out.println(d);
} catch (ParseException e) { e.printStackTrace();
}
为什么打出来的还是Tue Oct 10 20:22:10 CST 2006
而不是:2006-10-10 20:22:10
如何能让、Date d=formater.parse(datevalue);
System.out.println(d);
打出的是2006-10-10 20:22:10
SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date d=formater.parse(datevalue);
System.out.println(d);
} catch (ParseException e) { e.printStackTrace();
}
为什么打出来的还是Tue Oct 10 20:22:10 CST 2006
而不是:2006-10-10 20:22:10
如何能让、Date d=formater.parse(datevalue);
System.out.println(d);
打出的是2006-10-10 20:22:10
SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date d = formater.parse(datevalue);
System.out.println(formater.format(d));
} catch (ParseException e) {
e.printStackTrace();
}
System.out.println(d);
直接打印Date类对象d,会默认调用d.toString();方法,而此方法打印格式就是:
Tue Oct 10 20:22:10 CST 2006
要打印你需要的格式应该:
System.out.println(formater.format(d));