jodatime - Joda-Time 的运行时间

标签 jodatime

我有一个 DateTime我需要查看它是否是过去 10 年或更长时间的对象(想想即将过期的证书)。我是 Joda-Time 的新手,那是怎么做到的?感谢您的帮助。

最佳答案

您需要查看 docs for the DateTime class .但为了让您行动起来,支票将类似于以下内容:

1) 您需要构造一个代表 10 年前的 DateTime...

// Build a DateTime for exactly 10 years ago.

DateTime tenYearsAgo = new DateTime(); // should give you a DateTime representing 'now' 
tenYearsAgo = tenYearsAgo.minusYears(10);            // should give you 10 years ago

2) ...并使用 DateTime.isBefore 进行比较。

// Let's assume the DateTime you're comparing is called 'myDateTime'.

if (myDateTime.isBefore(tenYearsAgo)) { /* do something */ }
else { /* do something else */ }

请注意,日历有一些微妙之处,Joda 为您做了很好的抽象工作;在深入了解之前,您真的很想研究一下文档。

关于jodatime - Joda-Time 的运行时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3198154/

相关文章:

java - JodaTime:如何在不同时区找到 future 时间

java - 使用 jodatime 从字符串日期获取日期名称

java - 2020-04-03 20 :17:46 to "yyyy-MM-dd' T'HH:mm:ss"format

java - 将 Sugar ORM 与 UUID 或 Joda-Time 结合使用

android - Android : The datetime zone id 'America/New_York' is not recognised 中的 Joda-Time 错误

java - 尝试解析 json 时出现 NoSuchFieldError "ADJUST_DATES_TO_CONTEXT_TIME_ZONE"

scala - 如何使用joda时间在scala中将dd/mm/yyyy转换为yyyymmdd

android - Joda time forPattern 不能正确处理 4 位数年份

java - 如何使用 Joda 时间找到最近的月末日期?