Parsing a date on Twitter with Joda Time

Twitter gives me a date like "Wed, 27 Mar 2013 15:12:14 +0000." I am trying to parse it with:

DateTimeFormat.forPattern("EEE, dd MMM yyyy HH:mm:ss ZZZZZ").withLocale(Locale.ENGLISH);

But he fails:

Invalid format: "Wed, 03 Apr 2013 10:35:35 +0000" is malformed at "+0000"

I tried replacing ZZZZZwith z, zand ZZZ, but no change. Can these dates be analyzed in this way?

+5
source share
2 answers

Although you said you use the template Zin the format template, this works:

DateTimeFormatter format = 
    DateTimeFormat.forPattern("EEE, dd MMM yyyy HH:mm:ss Z").withLocale(Locale.ENGLISH);
DateTime dateTime = format.parseDateTime("Wed, 27 Mar 2013 15:12:14 +0000");

When parsing this format, one time zone character is sufficient Z, 4 is invalid:

Z time zone offset / identification zone -0800; -08: 00; America / Los _Angeles

See javadoc for details

+7
source

, , API, . :

DateTimeFormatter format = DateTimeFormat.forPattern("EE MMM dd HH:mm:ss Z yyyy").withLocale(Locale.ENGLISH)
String input = "Sat Jan 14 01:50:54 +0000 2017"
DateTime dateTime = format.parseDateTime(input)
0

All Articles