我使用下面的代码来解析日期,并按照我想要的格式化它;该代码适用于其他日期,例如:
Thu,2014年9月4日19:32:00 GMT
但它会在以下日期抛出上述错误消息:
Fri,05 Sep 2014 06:01:00 +0100
任何人都可以解释原因吗?
感谢。
代码:
//Only get the 'important' parts.
pubDateFormat = pubDate.substring(0, 23);
//Format it how I want.
dateFormatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm");
//Here is where it is breaking.
Date date = dateFormatter.parse(pubDateFormat);
//Format it once again to how I want.
dateFormatter = new SimpleDateFormat("dd/MM/yyyy");
//get the current date and format it the same.
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
currDate = sdf.format(new Date());
currDate = currDate.replace(" ", "");
rssDate = dateFormatter.format(date).replace(" ", "");
这是日志:
09-05 11:30:07.153: E/DATE(7665): Fri, 05 Sep 2014 06:01
09-05 11:30:07.153: E/ERROR(7665): java.text.ParseException: Unparseable date: "
09-05 11:30:07.153: E/ERROR(7665): Fri, 05 Sep 2014 06:01" (at offset 0)
答案 0 :(得分:0)
您必须添加区域设置:
SimpleDateFormat dateFormatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm", Locale.ENGLISH);
答案 1 :(得分:0)
试试这个
DateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm", Locale.US);