Reputation: 2503
Im trying to parse the following date:
Wed Aug 27 13:08:45 +0000 2008
(Is for Twitter API 1.1)
I make the following format:
/**
* Large twitter date format sample: "Wed Aug 27 13:08:45 +0000 2008"
*/
private static final String LARGE_TWITTER_DATE_FORMAT = "EEE MMM dd HH:mm:ss Z yyyy";
but it says:
java.text.ParseException: Unparseable date: "Sun Dec 25 14:49:28 +0000 2011" (at offset 0)
at java.text.DateFormat.parse(DateFormat.java:626)
What im doing wrong?
Thanks
Upvotes: 1
Views: 3087
Reputation: 3899
The following works for me
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class Test {
private static final String LARGE_TWITTER_DATE_FORMAT = "EEE MMM dd HH:mm:ss Z yyyy";
/**
* @param args
*/
public static void main(String[] args) {
SimpleDateFormat df = new SimpleDateFormat(LARGE_TWITTER_DATE_FORMAT);
try {
System.out.println(df.parse("Wed Aug 27 13:08:45 +0000 2008 "));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Upvotes: -1
Reputation: 10789
I think this is locale issue. Running that code on my machine gives me expected result with no exception.
Hint: Parsing for ENGLISH
locale works good
String LARGE_TWITTER_DATE_FORMAT = "EEE MMM dd HH:mm:ss Z yyyy";
String twiDate = "Wed Aug 27 13:08:45 +0000 2008";
new SimpleDateFormat(LARGE_TWITTER_DATE_FORMAT, Locale.ENGLISH)
.parse(twiDate).getHours());
Parsing for FRANCE locale
causes the same error that you have
String LARGE_TWITTER_DATE_FORMAT = "EEE MMM dd HH:mm:ss Z yyyy";
String twiDate = "Wed Aug 27 13:08:45 +0000 2008";
System.out.println(new SimpleDateFormat(LARGE_TWITTER_DATE_FORMAT, Locale.FRANCE)
.parse(twiDate).getHours());
Upvotes: 4