public class testSortDate { public void runApp() { String s1 = "2017-08-10 22:18:22"; String s2 = "2018-08-10 22:18:22"; String s3 = "2017-08-10 22:19:22"; List<String> arr = new ArrayList<>(); arr.add(s1); arr.add(s2); arr.add(s3); DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // new->old排序,首先将字符型的日期转换为日期类型。 arr.sort((a1, a2) -> { try { return df.parse(a1).compareTo(df.parse(a2)); } catch (ParseException e) { e.printStackTrace(); } return 1; }); } }
参考链接:https://blog.csdn.net/u012560212/article/details/78023034