Hi:

Following the javadoc for DateTimeFormatters.isoDateTime():

Returns the ISO date formatter that prints/parses a date, with the offset and zone if available, such as '2007-12-03T10:15:30', '2007-12-03T10:15:30+01:00' or '2007-12-03T10:15:30+01:00[Europe/Paris]'.

I try to parse these three examples (code is below).

1) The last one fails, perhaps javadocs are out of date?

2) More generally, how do I know which XXXDateTime class to use, assuming I want to handle flexible input? Am I missing something simpler to use?

thanks


public class TestThreeten  extends TestCase {

  public TestThreeten(String name) {
    super(name);
  }

  void testParse(String s) {
    DateTimeFormatter dtf = DateTimeFormatters.isoDateTime();

    try {
      dtf.parse(s);
    } catch (Exception e) {
      System.out.printf("DateTimeFormatter Exception = %s%n", e.getMessage());
      return;
    }

    try {
      ZonedDateTime date = ZonedDateTime.parse(s, dtf);
      System.out.printf("%s = %s%n",s, date);
    } catch (Exception e) {
      System.out.printf("ZonedDateTime Exception = %s%n", e.getMessage());
    }
    System.out.printf("%n");
  }

  public void testIsoDateTime()  {
    testParse("2007-12-03T10:15:30");
    testParse("2007-12-03T10:15:30+01:00");
    testParse("2007-12-03T10:15:30+01:00[Europe/Paris]");
  }

}

gives:

ZonedDateTime Exception = Text '2007-12-03T10:15:30' could not be parsed into ZonedDateTime but was parsed to {ISO.LocalDateTime=2007-12-03T10:15:30}

ZonedDateTime Exception = Text '2007-12-03T10:15:30+01:00' could not be parsed into ZonedDateTime but was parsed to {ISO.OffsetDateTime=2007-12-03T10:15:30+01:00}

DateTimeFormatter Exception = Text '2007-12-03T10:15:30+01:00[Europe/Paris]' could not be parsed, unparsed text found at index 25