Date has before and after methods and can be compared to each other as follows: (日期有之前和之后的方法,可以相互比较 ,如下所示:)
if(todayDate.after(historyDate) && todayDate.before(futureDate)) {
// In between
}
For an inclusive comparison: (进行包容性比较:)
if(!historyDate.after(todayDate) && !futureDate.before(todayDate)) {
/* historyDate <= todayDate <= futureDate */
}
You could also give Joda-Time a go, but note that: (您也可以尝试一下Joda-Time ,但请注意:)
Joda-Time is the de facto standard date and time library for Java prior to Java SE 8. Users are now asked to migrate to java.time ( JSR-310 ). (Joda-Time是Java SE 8之前的Java的事实上的标准日期和时间库。现在,要求用户迁移到java.time ( JSR-310 )。)
Back-ports are available for Java 6 and 7 as well as Android. (反向端口适用于Java 6和7以及Android。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…