对List中的数据根据时间排序-倒序

private static void ListSort(List list) {
        Collections.sort(list, new Comparator() {
            @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;
            }
        });
    }

你可能感兴趣的:(java)