generate hour timestamp for week

32 views
Skip to first unread message

sujeet jog

unread,
Sep 19, 2016, 1:45:25 PM9/19/16
to scala-user
Hi, 

I'm a new to scala,  wanted to know how to generate hourly timestamp for a week , 

In python i do it like below, can you please let me know if we have something similar in scala.

dIndex = pd.date_range('02/12/2016', periods = 168, freq = "H")

date = []

for i in list(dIndex.to_pydatetime()) :
        print(str(i))


satorg

unread,
Sep 21, 2016, 1:37:00 AM9/21/16
to scala-user
Hi.

If I understand you correctly, you may want to make use of the Joda Time library (included in Java 8).
So, assuming you're at Java 8, the desired code can look like the following:

import java.time._

val tsStart = LocalDate.of(2016, 12, 2).atStartOfDay

for(ts <- Iterator.iterate(tsStart)(_ plusHours 1).take(168))
  println
(ts) // use ts.format(...) here if necessary

Reply all
Reply to author
Forward
0 new messages