【发布时间】:2017-04-03 20:10:18
【问题描述】:
我有一个这样的 Joda DateTimes 数组列表:
List <DateTime> nextRemindersArray = new ArrayList<DateTime>();
nextRemindersArray.add(reminderOneDateTime);
nextRemindersArray.add(reminderTwoDateTime);
nextRemindersArray.add(reminderThreeDateTime);
我正在尝试按升序对日期进行排序,但遇到了问题:
我google了一下,找到了这个页面:
https://cmsoftwaretech.wordpress.com/2015/07/19/sort-date-with-timezone-format-using-joda-time/
我试过这样:
nextRemindersArray.sort(nextRemindersArray);
但它给了我错误:
Error:(1496, 37) error: incompatible types: List<DateTime> cannot be converted to Comparator<? super DateTime>
然后我这样尝试:
DateTimeComparator dateTimeComparator = DateTimeComparator.getInstance();
nextRemindersArray.sort(nextRemindersArray, dateTimeComparator);
还有这样的:
nextRemindersArray.sort(nextRemindersArray, new DateTimeComparator());
但都有错误。
我尝试了 Joda 时间手册,但没有太大帮助。如何对数组进行排序?
提前感谢您的帮助
【问题讨论】:
标签: sorting datetime arraylist jodatime comparator