Java对日期时间值的集合进行排序
发布时间:2020-12-15 04:29:17 所属栏目:Java 来源:网络整理
导读:我正在使用notes.jar lotus notes api来提取电子邮件的日期和时间.当我将它们添加到集合中时,如果像这样添加它们: Vector times = doc.getItemValueDateTimeArray("PostedDate"); for (int j=0; jtimes.size(); j++) { Object time = times.elementAt(j); i
我正在使用notes.jar lotus notes api来提取电子邮件的日期和时间.当我将它们添加到集合中时,如果像这样添加它们:
Vector times = doc.getItemValueDateTimeArray("PostedDate"); for (int j=0; j<times.size(); j++) { Object time = times.elementAt(j); if (time.getClass().getName().endsWith("DateTime")) { String Listadd = ((DateTime)time).getLocalTime(); NotesDates.add((DateTime)time); 我收到错误: lotus.domino.local.DateTime cannot be cast to java.lang.Comparable 当我将值添加为String时代码运行,但我无法对集合进行排序. 如何对日期和时间的集合进行排序以找到最早和最新的? 解决方法
你有几个选择.这是两个.
>使用java.util.Date的集合而不是lotus.domino.local.DateTimeLotus注释DateTime对象有一个方法toJavaDate(),java.util.Date为你实现了Comparable接口>为lotus.domino.local.DateTime对象实现自定义比较器.最好将日期再次转换为java日期,并使用它的比较方法,而不是重新发明轮子. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |