比较 2 个日期 javafx
Comparing 2 dates javafx
我正在编写一个基于 javafx/hibernate 的应用程序。现在我
当我想用已售出的商品制作新的 table 时遇到问题
最近 7/30/365 天(或选择的自定义日期)。
- 文章以当前日期存储在数据库中 (
Date articleDate = new Date();
)
- 所有文章都是在程序启动时从数据库中获取的,它们位于名为
articlesDBList
的 ObserveList
中。
到目前为止我尝试了什么:
ObserveList<ArticlesDB> sortForSevenDays =FXCollections.observableArrayList();
for(ArticleDB article: articleDBList) {
if() { //missing statement for comparing articles by date for past 7 days
sortForSevenDays.add(article);
}
}
在mkyong there are 3 possibilities in comparing Date
in Java. In the comment section even the better choice (IF Javaversion < 8) of Joda-Time上呈现。
没有 Joda 的最简单的解决方案可能只是使用 Calendar
:
进行比较
Calendar articleCal = Calendar.getInstance();
articleCal.setTime(articleDate);
//check for past 7 days
Calendar check = Calendar.getInstance();
check.add(Calendar.DATE, -7);
if(articleCal.after(check))
sortForSevenDays.add(article);
信息:请记住,这比较正好是 7 天(包括分钟等)。
我正在编写一个基于 javafx/hibernate 的应用程序。现在我 当我想用已售出的商品制作新的 table 时遇到问题 最近 7/30/365 天(或选择的自定义日期)。
- 文章以当前日期存储在数据库中 (
Date articleDate = new Date();
) - 所有文章都是在程序启动时从数据库中获取的,它们位于名为
articlesDBList
的ObserveList
中。
到目前为止我尝试了什么:
ObserveList<ArticlesDB> sortForSevenDays =FXCollections.observableArrayList();
for(ArticleDB article: articleDBList) {
if() { //missing statement for comparing articles by date for past 7 days
sortForSevenDays.add(article);
}
}
在mkyong there are 3 possibilities in comparing Date
in Java. In the comment section even the better choice (IF Javaversion < 8) of Joda-Time上呈现。
没有 Joda 的最简单的解决方案可能只是使用 Calendar
:
Calendar articleCal = Calendar.getInstance();
articleCal.setTime(articleDate);
//check for past 7 days
Calendar check = Calendar.getInstance();
check.add(Calendar.DATE, -7);
if(articleCal.after(check))
sortForSevenDays.add(article);
信息:请记住,这比较正好是 7 天(包括分钟等)。