java.text.ParseException: Unparseable date: "2011-11-11 03:03PM"
2011年4月12日
代码如下:
[java]
Date date = new Date();
DateFormat f=new SimpleDateFormat("yyyy-MM-dd hh:mma");
String str = "2011-11-11 03:03PM";
try {
Date dat = f.parse(str);
System.out.println(dat);
} catch (ParseException e) {
e.printStackTrace();
}
[/java]
问题出在PM上,如果是“下午”就没问题了,
所以要把DateFormat f=new SimpleDateFormat(“yyyy-MM-dd hh:mma”);
改为DateFormat f=new SimpleDateFormat(“yyyy-MM-dd hh:mma”,Locale.ENGLISH);