Markus
Markus

Reputation: 3782

How to put the range of dates in a specific format?

I am using Joda time to generate a range of dates as follows:

val now = DateTime.now
(0 until 5).map(now.minusDays(_)).foreach(println)

How can I parse the generated dates to yyyy-MM-dd format. I was getting the error "java.lang.IllegalArgumentException: Invalid format" when using DateTimeFormat:

val dtf = DateTimeFormat.forPattern("yyyy-MM-dd")
(0 until 5).map(now.minusDays(_)).foreach(d=>dtf.parseDateTime(d.toString))

Upvotes: 0

Views: 137

Answers (1)

Andrzej Jozwik
Andrzej Jozwik

Reputation: 14649

Change to:

val now = DateTime.now
(0 until 5).map(now.minusDays(_)).map(d=> d.toString("yyyy-MM-dd"))

Upvotes: 1

Related Questions