我有两个变量:
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格式返回日期集合。