Joda Time,同时解析小时和时钟

发布于 11-28 05:59 字数 1081 浏览 1 评论 0原文

我想要一个日期时间解析器,它可以解析“正常”时间或时钟时间的时间。 意味着我可以同时拥有 00:00:0024: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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深海夜未眠2024-12-05 05:59:04

时钟 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 sense 24:00:00 is never equal to 00:00:00.

衣神在巴黎2024-12-05 05:59:04

Joda-Time不支持解析24:00。如果您想解析它,您需要自己实现 DateTimeParser 并使用 DateTimeFormatterBuilder 集成它。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文