我有Seq
Seq((date1, date2), (date1, date3))
我需要通过将两个日期比较成元组来过滤此Seq。例如:date1.isBefore(date2)
答案 0 :(得分:-1)
这可能会有所帮助。最后有几个不同的示例,它们交换了比较日期的顺序,这可能会有用。
scala> val date1 = new java.util.Date(System.currentTimeMillis())
val date1: java.util.Date = Wed Sep 23 11:21:24 PDT 2020
scala> val date2 = new java.util.Date(System.currentTimeMillis())
val date2: java.util.Date = Wed Sep 23 11:21:28 PDT 2020
scala> val xs = Seq((date1,date2))
val xs: Seq[(java.util.Date, java.util.Date)] = List((Wed Sep 23 11:21:24 PDT 2020,Wed Sep 23 11:21:28 PDT 2020))
scala> xs.filter(t => t._1.before(t._2))
val res1: Seq[(java.util.Date, java.util.Date)] = List((Wed Sep 23 11:21:24 PDT 2020,Wed Sep 23 11:21:28 PDT 2020))
scala> xs.filter(t => t._2.before(t._1))
val res2: Seq[(java.util.Date, java.util.Date)] = List()