Joda时间解析时间超过24小时

Joda time parsing time with more than 24 hour

是否有可能解析日期为“2016-07-13T25:50”的时间以获取值为“2016-07-14T01:50”的 LocalDateTime?我只想使用 Joda 时间和 java.util.

如果不编写自定义解析器似乎是不可能的,因为 Joda 和 Java 8 DateTime API(主要受 Joda 启发)与 ISO-8601 日历系统一起工作,但不' 允许这种格式。

Wikipedia关于持续时间的引述:

Alternatively, a format for duration based on combined date and time representations may be used by agreement between the communicating parties either in the basic format PYYYYMMDDThhmmss or in the extended format P[YYYY]-[MM]-[DD]T[hh]:[mm]:[ss]. For example, the first duration shown above would be "P0003-06-04T12:30:05". However, individual date and time values cannot exceed their moduli (e.g. a value of 13 for the month or 25 for the hour would not be permissible).

API docs 中提供了可用的 DateTimeFormatters 列表。

您可以在 Joda-Time 中使用宽松的年表:

LenientChronology lenientChrono = LenientChronology.getInstance(ISOChronology.getInstance());
DateTimeFormatter formatter = 
  DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm").withChronology(lenientChrono);
LocalDateTime ldt = formatter.parseLocalDateTime("2016-07-13T25:50");
System.out.println("lenient=" + ldt); // 2016-07-14T01:50:00.000