I want to generate a data as epoch millis for each day for a month in Scala. If anybody has done this before, please help on it.
Asked
Active
Viewed 218 times
-4
-
3StackOverflow rewards effort. Show us what you've tried so far. Post code that doesn't work so we can better address where you might be going off track. At the very least, tell us what libraries you've looked at or looked for as part of your investigation. – jwvh Dec 06 '18 at 09:32
-
1At least tell us what your search and research brought up and in what way it fell short of giving you what you need for solving your task. – Ole V.V. Dec 06 '18 at 09:35
1 Answers
1
Use YearMonth
(java.time.YearMonth
, that is) for defining your month. yourYearMonth.atDay(1)
will give you the first of the month. yourYearMonth.plusMonths(1)
will give you the following month, get the first of that month too. Now use LocalDate.datesUntil
to get a stream of all the days of the month. In your stream pipeline use LocalDate.atStartOfDay(ZoneId)
to get the first moment of each day. Convert it first to an Instant
, then to milliseconds since the epoch.
Links
- Oracle tutorial: Date Time explaining how to use
java.time
. - Documentation of
YearMonth
,LocalDate
,ZonedDateTime
andInstant
.