我使用jodatime
使用以下代码生成了一个日期数组import org.joda.time.{DateTime, Period}
import org.joda.time.format.DateTimeFormat
import java.text.SimpleDateFormat
def dateRange(from: DateTime, to: DateTime, step: Period): Iterator[DateTime]
=Iterator.iterate(from)(_.plus(step)).takeWhile(!_.isAfter(to))
val from = new DateTime(2000, 06, 30,0,0,0,0)
val to = new DateTime(2001, 06, 30,0,0,0,0)
val by = new Period(0,2,0,0,0,0,0,0)
val range = { dateRange(from ,to, by)}
val dateRaw = (range).toArray
如何将DateTimeFormat.forPattern("YYYYMMdd")
传递给每个值以获取格式为yyyyMMdd的整数数组
Array [Int] = Array(20000630,20000830,20001030 ......
答案 0 :(得分:1)
val f = DateTimeFormat.forPattern("YYYYMMdd")
dateRaw.map(d => f.print(d).toInt)