scalacode
scalacode

Reputation: 1106

calculate date from String in scala

Hello I want to convert these kinds of Strings into Date using the LocalDateTime JAVA API . Below is the input Strings : "1672017" that I want to convert to the corresponding date based on the date whose number is 167 in the year 2017.

Any idea how to do this please

Upvotes: 1

Views: 98

Answers (1)

xingbin
xingbin

Reputation: 28279

D represents day of year, so you can use

DateTimeFormatter format = DateTimeFormatter.ofPattern("DDDyyyy");
LocalDate localDate = LocalDate.parse("1672017", format);

Upvotes: 8

Related Questions