private static void ListSort(List<News> list) {
Collections.sort(list, new Comparator<News>() {
@Override
public int compare(News n1, News n2) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
Date dt1 = format.parse(Jsoup.parse(new String(n1.getCrTime())).text());
Date dt2 = format.parse(Jsoup.parse(new String(n2.getCrTime())).text());
if (dt1.getTime() > dt2.getTime()) {
return -1;
} else if (dt1.getTime() < dt2.getTime()) {
return 1;
} else {
return 0;
}
} catch (Exception e) {
e.printStackTrace();
}
return 0;
}
});
}
对List中的数据根据时间排序-倒序
最新推荐文章于 2024-06-25 09:09:51 发布