Joda Time,同时解析小时和时钟
我想要一个日期时间解析器,它可以解析“正常”时间或时钟时间的时间。 意味着我可以同时拥有 00:00:00
或 24:00:00
。 进一步的时钟时间仅允许在午夜进行。表示不允许 24:00:01
。这必须表示为 00:00:01
。 这可以以某种方式实现吗? 我的解析器目前不尊重时钟时间:
//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();
如果有人可以帮助我,那就太好了。
此致, 弗洛里安
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
时钟 24 点相当于 23:00。允许使用 kk:mm:ss
24:00:01
格式。因此从这个意义上说,24:00:00
永远不等于00:00:00
。Clock hour 24 would equate to 23:00. Using the format kk:mm:ss
24:00:01
would be allowed. So in that sense24:00:00
is never equal to00:00:00
.