I found some kind of misbehavior in JodaTime when parsing a time instant.
DateTimeFormatter dateStringFormat =
DateTimeFormat.forPattern("EEE MMM dd kk:mm:ss 'GMT'Z yyyy");
DateTime startTime = dateStringFormat.withOffsetParsed().
parseDateTime("Tue Jan 01 09:30:00 GMT+2000 2013");
DateTime endTime = dateStringFormat.withOffsetParsed().
parseDateTime("Tue Jan 05 10:31:00 GMT+2000 2013");
Period period = new Period(startTime, endTime);
PeriodFormatter formatter = new PeriodFormatterBuilder().appendDays()
.appendSuffix(" day ", " days")
.appendHours()
.appendSuffix(" hour ", " hours")
.appendMinutes()
.appendSuffix(" minute", " minutes")
.toFormatter();
System.out.println(formatter.print(period));
Output is: "1 hour 1 minute"
Where is the "days" part ?
Basil Bourque's version of this code…
The day-of-month is inexplicably being parsed as 01 rather than 05 in the second DateTime.
DateTimeFormatter dateStringFormat = DateTimeFormat.forPattern("EEE MMM dd kk:mm:ss 'GMT'Z yyyy");
DateTime startTime = dateStringFormat.withOffsetParsed().parseDateTime("Tue Jan 01 09:30:00 GMT+2000 2013");
DateTime endTime = dateStringFormat.withOffsetParsed().parseDateTime("Tue Jan 05 10:31:00 GMT+2000 2013");
Dump to console…
System.out.println( "startTime: " + startTime );
System.out.println( "endTime: " + endTime );
When run…
startTime: 2013-01-01T09:30:00.000+20:00
endTime: 2013-01-01T10:31:00.000+20:00