Reputation: 461
I want to have a DateTime Parser that can parse a time that is either in "normal" hours or in clockhours.
Means that I can have 00:00:00
or 24:00:00
at the same time.
Further clockhour is only allowed for midnight. Means 24:00:01
is not allowed. This must be expressed as 00:00:01
.
Is this somehow achievable?
My parser currently does not respect clockhours:
//The formatter for the timezone
DateTimeFormatter timezoneFormatter = new DateTimeFormatterBuilder().appendTimeZoneOffset(null, true, 2, 2)
.toFormatter();
//The formatter for the fractional (3 digit) seconds
DateTimeFormatter fractionalSecondsFormatter = new DateTimeFormatterBuilder().appendLiteral('.')
.appendFractionOfSecond(3, 3).toFormatter();
// Here a parser is created that parses a string of the form HH:mm:ss. Further the string may have
// 3 digit fractional seconds (with a dot as prefix) and may have a timezone.
DATE_TIME_PARSER = new DateTimeFormatterBuilder().appendHourOfDay(2).appendMinuteOfHour(2).appendSecondOfMinute(2)
.appendOptional(fractionalSecondsFormatter.getParser()).appendOptional(timezoneFormatter.getParser())
.toFormatter();
Would be greate if someone could help me.
Best regards, Florian
Upvotes: 3
Views: 1325
Reputation: 63395
Joda-Time does not support parsing of 24:00. If you want to parse that you'll need to implement DateTimeParser
yourself and intergrate it using DateTimeFormatterBuilder
.
Upvotes: 0
Reputation: 513
Clock hour 24 would equate to 23:00. Using the format kk:mm:ss 24:00:01
would be allowed. So in that sense 24:00:00
is never equal to 00:00:00
.
Upvotes: 2