Result of TimeZone.getDefault() - sun.util.calendar.ZoneInfo[id="Europe/London",offset=0,dstSavings=3600000,useDaylight=true,transitions=242,lastRule=java.util.SimpleTimeZone[id=Europe/London,offset=0,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]]
Result of DateTimeZone.getDefault() - Europe/London
Problem description
Maybe the answer is migrate to java.time, but for what it's worth, with time-only format Hmmss, joda-time parses the wrong time or throws exception.
Test case
joda-time
public void testFormatParse_Hmmss() {
DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("Hmmss").withZoneUTC();
DateTime parsed = dateFormatter.parseDateTime("03030");
assertEquals(0, parsed.getHourOfDay()); // AssertionFailedError: expected:<0> but was:<3>
assertEquals(30, parsed.getMinuteOfHour());
parsed = dateFormatter.parseDateTime("71532"); // IllegalFieldValueException: Cannot parse "71532": Value 71 for hourOfDay must be in the range [0,23]
assertEquals(7, parsed.getHourOfDay());
assertEquals(15, parsed.getMinuteOfHour());
}
Key information
TimeZone.getDefault()
- sun.util.calendar.ZoneInfo[id="Europe/London",offset=0,dstSavings=3600000,useDaylight=true,transitions=242,lastRule=java.util.SimpleTimeZone[id=Europe/London,offset=0,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]]DateTimeZone.getDefault()
- Europe/LondonProblem description
Maybe the answer is migrate to
java.time
, but for what it's worth, with time-only formatHmmss
, joda-time parses the wrong time or throws exception.Test case
joda-time
java.time