Twitter date unparseable?
Your format string works for me, see:
public static Date getTwitterDate(String date) throws ParseException {
final String TWITTER="EEE MMM dd HH:mm:ss ZZZZZ yyyy";
SimpleDateFormat sf = new SimpleDateFormat(TWITTER);
sf.setLenient(true);
return sf.parse(date);
}
public static void main (String[] args) throws java.lang.Exception
{
System.out.println(getTwitterDate("Thu Dec 3 18:26:07 +0000 2010"));
}
Output:
Fri Dec 03 18:26:07 GMT 2010
UPDATE
Roland Illig is right: SimpleDateFormat is Locale dependent, so
just use an explicit english Locale:
SimpleDateFormat sf = new SimpleDateFormat(TWITTER,Locale.ENGLISH);
Maybe you are in a locale where ‘Tue‘ is not a recognized day of week, for example German. Try to use the ‘SimpleDateFormat‘ constructor that accepts a ‘Locale‘ as a parameter, and pass it ‘Locale.ROOT‘.
This works for me ;)
public static Date getTwitterDate(String date) throws ParseException
{
final String TWITTER = "EEE, dd MMM yyyy HH:mm:ss Z";
SimpleDateFormat sf = new SimpleDateFormat(TWITTER, Locale.ENGLISH);
sf.setLenient(true);
return sf.parse(date);
}