JodaTime 从周期中获取值
我有两个日期时间,一个是“自从”和“现在”的时间,
我需要的是获取那时之间的时间。
我的问题是我想要得到它的格式:
示例: 自 = '2010 年 4 月 17 日' now = '2011 年 4 月 15 日'
我想要 '0 年 11 个月 29 天'
如果现在是 '2010 年 4 月 13 日',结果应该是这样的: “1年0个月2天”
但是这个逻辑让我很困惑。
I have two DateTimes, one is the time 'since' and 'now'
What I need, is get the time between then.
My problem is into the format I want to get it:
Example:
since = '17 april 2010'
now = '15 april 2011'
I want to have '0 years, 11 months, 29 days'
And in case since is '13 april 2010' the result should be like:
'1 years, 0 months, 2 days'
But this logic is puzzling me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不完全确定我明白你的问题。听起来像您想要的:
如果不是这样,您能提供更多详细信息吗?
I'm not entirely sure I follow your question. It sounds like you want:
If that isn't the case, could you give more details?
java.time
下面引用的是 主页的通知乔达时间:
使用现代日期时间 API
java.time
的解决方案:Period# Between
获取之间的时间段两个LocalDate
。parseCaseInsensitive
函数构建DateTimeFormatter
。区域设置
的情况下使用DateTimeFormatter
。演示:
输出:
在线演示< /a>
从 Trail 了解有关现代日期时间 API 的更多信息:日期时间。
* 无论出于何种原因,如果您必须坚持使用 Java 6 或 Java 7,您可以使用 ThreeTen-Backport 将大部分 java.time 功能向后移植到 Java 6 和 Java 6 7. 如果您正在处理 Android 项目,并且您的 Android API 级别仍然不符合 Java-8,请检查 通过脱糖提供 Java 8+ API 和 如何在Android项目中使用ThreeTenABP。
java.time
Quoted below is a notice from the home page of Joda-Time:
Solution using
java.time
, the modern Date-Time API:Period#between
to get the period between twoLocalDate
s.DateTimeFormatter
usingparseCaseInsensitive
function.DateTimeFormatter
without aLocale
.Demo:
Output:
ONLINE DEMO
Learn more about the modern Date-Time API from Trail: Date Time.
* For any reason, if you have to stick to Java 6 or Java 7, you can use ThreeTen-Backport which backports most of the java.time functionality to Java 6 & 7. If you are working for an Android project and your Android API level is still not compliant with Java-8, check Java 8+ APIs available through desugaring and How to use ThreeTenABP in Android Project.