我无法弄清楚为什么这段代码不起作用。任何人都可以帮我无法解析字符串日期格式
String dateStr = "Thu Apr 02 09:49:16 CEST 2015";
DateFormat readFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
DateFormat writeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = null;
try {
date = readFormat.parse(dateStr);
} catch (ParseException e) {
e.printStackTrace();
}
String formattedDate = "";
if (date != null) {
formattedDate = writeFormat.format(date);
}
System.out.println(formattedDate);
我的阅读格式应该是好的,除非我失去了一些东西。
我总是得到一个java.text.ParseException:无法解析的日期: “周四4月2日9时49分16秒CEST 2015”
在线:日期= readFormat.parse(dateStr);
我试过http://ideone.com/oBwtQo上的代码,它也在那里工作。为什么不在我的PC上的NetBeans中进行此项工作。