Joda Time String to DateTime conversion

I require some help converting the following Thu, 13 Feb 2014 16:43:58 +0000 string to type DateTime. I have a stream of tweets being stored in an ElasticSearch cluster, currently the timestamp of each tweet is mapped as a string. I wish to parse these to type DateTime.

I tried EEE, dd MMM yyyy HH:mm:ss ZZZZZ but it failed. Any help would be great.

Thanks.

Jon Skeet
people
quotationmark

You only want a single Z to represent "offset without a colon".

Also note that you should ensure that your DateTimeFormatter is using English month/day names.

For example:

import java.util.*;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

class Test {
    public static void main(String[] args) throws Exception {
        DateTimeFormatter format =
            DateTimeFormat.forPattern("EEE, dd MMM yyyy HH:mm:ss Z")
                .withLocale(Locale.US);
        String text = "Thu, 13 Feb 2014 16:43:58 +0000";
        System.out.println(format.parseDateTime(text));
    }
}

people

See more on this question at Stackoverflow