I have some function that gets as an input specific starting-timestamp and end-timestamp (e.g. "2018-01-01 16:00:00" and "2018-01-01 17:00:00") (in the beginning of the code i import java.sql.Timestamp
)
I want to iterate this function over time (e.g. - between 2018-01-01 until 2018-01-10, over each hour separately).
The furthest I got so far was iterating over the date, using import java.time.{LocalDate, Period}
but when I tried to change my code to import java.time.{LocalDateTime, Period}
, it didn't work:
import java.time.temporal.ChronoUnit
import java.time.temporal.ChronoField.HOUR_OF_DAY
import java.time.{LocalDateTime, Period}
val start = LocalDateTime.of(2018, 1, 1,6,20)
val end = LocalDateTime.of(2018, 1, 11,6,30)
val dates: IndexedSeq[LocalDateTime] =
(0L to (end.toEpochSecond() - start.toEpochSecond())).map(hours =>
start.plusHours(hours)
)
dates.foreach(println)
Would highly appreciate your help!