Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Joda time parsing time with more than 24 hour

Is there possible parse time with date like "2016-07-13T25:50" to get LocalDateTime with value "2016-07-14T01:50"? I want to use only Joda time and java.util.

like image 205
OrdinaryNick Avatar asked Mar 11 '23 17:03

OrdinaryNick


1 Answers

You can use a lenient chronology in 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
like image 169
Meno Hochschild Avatar answered Mar 17 '23 00:03

Meno Hochschild