Question

parseDateTime() consistently returns a date about 23 days in the future. My local is Spain, so I'm UTC+2. Does anyone know why it would be doing this? I'm probably making an obvious mistake.

I'm using Joda 2.2 and JavaSE 1.7.

public class JodaTest {
private static final String INPUT_DATE = "Monday, 03 Jun 2013 20:54:20 -0700";

public static void main(String[] args) {
    DateTimeFormatter dtf = DateTimeFormat.forPattern("E, ee MMM YYYY HH:mm:ss Z");

    DateTime dt = dtf.parseDateTime(INPUT_DATE);
    displayResults(dt);
    dt = new DateTime();
    displayResults(dt);
}

public static void displayResults(DateTime dt) {
    System.out.println("parsedDate: " + dt.toString());
}

}

Was it helpful?

Solution

You should use:

DateTimeFormatter dtf = DateTimeFormat.forPattern("E, dd MMM YYYY HH:mm:ss Z");

As dd is for "Day in month".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top