java.text.Parseexception, unparseble date at position 0? Android

I am using the below code to parse a date, and to format it how I want; the code is working fine for other dates such as this one:

Thu, 04 Sep 2014 19:32:00 GMT

But it is throwing the above error message on a date such as this:

Fri, 05 Sep 2014 06:01:00 +0100

Can anyone explain why?

Thanks.

The code:

//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(" ", "");

This is the log:

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)

您必须添加区域设置:

SimpleDateFormat dateFormatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm", Locale.ENGLISH);

尝试这个

DateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm", Locale.US);
链接地址: http://www.djcxy.com/p/18642.html

上一篇: 传递给Date构造函数的Javascript日期字符串会给出奇怪的结果

下一篇: java.text.Parseexception,位置0处的不可分段日期? Android的