且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 Java 8/jsr310 中格式化持续时间

更新时间:2023-01-17 08:35:15

jsr-310 中没有 period/duration-formatter,与 JodaTime 不同.并非 JodaTime 的每个功能都被移植到 JSR-310(例如也不是 PeriodType).反过来,JSR-310 有一些 JodaTime 没有的功能(例如本地化的工作日数字或带有调整器的策略模式方法).

There is no period/duration-formatter in jsr-310, different from JodaTime. Not every feature of JodaTime was ported to JSR-310 (for example also not PeriodType). And in reverse JSR-310 has some features which are not available in JodaTime (for example localized weekday numbers or the strategy pattern approach with adjusters).

Java 9 可能会引入某种内置的句点格式(从 S. Colebourne 阅读有关此内容的一些内容).

It might happen that Java 9 will introduce some kind of built-in period formatting (read something about this from S. Colebourne).

结论:JSR-310 和 JodaTime 并不完全兼容,因此可能需要做很多工作.我不会那么热衷于尽快移民.您是否需要 JodaTime 不提供的 JSR-310 特殊功能?

Conclusion: JSR-310 and JodaTime are not fully compatible to each other, so a lot of work can be required. I would not be so keen on migration as soon as possible. Do you need special features of JSR-310 which are not offered by JodaTime?

附加说明:您还应该意识到 joda period(包括从年到秒的所有单位)与 jsr310-period(仅年、月、日)或 jsr310-duration(仅小时)不完全兼容、分、秒和小数秒).

Additional note: You should also be aware of the fact that joda period (which includes all units from years to seconds) is not fully compatible with jsr310-period (only years, months, days) or jsr310-duration (only hours, minutes, seconds and fraction seconds).