如何正确创建带有格式化日期的字符串?

时间:2019-01-10 10:00:13

标签: scala

我有两个变量:

val dateFrom = "2018-01-15"
val dateTo = "2018-06-15"

如何制作在2个日期之间全天的字符串:

{20180115,20180116,...,20180614,20180615}

P.S。如您所见,最终结果中的日期格式为"yyyyMMdd"

那是我现在尝试的:

import org.joda.time.{DateTime, Days}

def getDaysInBetween(from: DateTime, to: DateTime): Int = Days.daysBetween(from, to).getDays

def getDatesInBetween(from: DateTime, to: DateTime): Seq[DateTime] = {
  val days = getDaysInBetween(from, to)
  (0 to days).map(day => from.plusDays(day))
}

getDatesInBetween函数以DateTime格式返回日期集合。

0 个答案:

没有答案