最佳答案
您需要查看 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/