2021년 8월 26일 목요일

[ Scala ] Date Rang Foreach 예시



[ Code ]

import java.time.LocalDate

import java.time.format.DateTimeFormatter


val format = DateTimeFormatter.ofPattern("yyyy-MM-dd")

val start_dt = LocalDate.parse("2020-02-01", format)

val end_dt = LocalDate.parse("2020-02-20", format)

val date_diff = end_dt.toEpochDay() - start_dt.toEpochDay()


for (i <- 0l to date_diff by 1) {

  val s = start_dt.plusDays(i)

  val f_date = start_dt.plusDays(i)

  val date = f_date.toString().replaceAll("-","")

  val date_s = f_date + " 00:00:00"

  val date_e = f_date + " 23:59:59"

  val yymm = date.slice(0,6)

  println(s)

}

import java.time.LocalDate

import java.time.format.DateTimeFormatter


val format = DateTimeFormatter.ofPattern("yyyy-MM-dd")

val start_dt = LocalDate.parse("2021-05-04", format)

val end_dt = LocalDate.parse("2021-05-31", format)

val date_diff = end_dt.toEpochDay() - start_dt.toEpochDay()




[ Result ]

2020-02-01
2020-02-02
2020-02-03
2020-02-04
...
2020-02-18
2020-02-19
2020-02-20



댓글 없음:

댓글 쓰기