Get a DateTime with an specific pattern with nscala-time

298 Views Asked by At

I am trying to get this pattern 'dd-MM-yyyy' with a variable of type DateTime

@{DateTimeFormat.forPattern("dd-MM-YYYY").parseDateTime(user.birthday.toString)}

But I am getting this error

java.lang.IllegalArgumentException: Invalid format: "2015-12-10T00:00:00.000Z" is malformed at "15-12-10T00:00:00.000Z"

Is there a way to do this with nscala-time?

makes a difference if I am using UTC?

UPDATE

For the moment I am casting to Date and doing this

@{Dates.format(user.birthday.toDate, "dd-MM-YYYY")}

But maybe is a better way without casting

thank you

1

There are 1 best solutions below

0
On

So, if I understood your question correctly, you are trying to achieve the following:

  1. Parse date from a string using a date format
  2. Print/Display the date in another format.

Try the below:

@{Dates.format(DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ").parseDateTime(user.birthday.toString), "dd-MM-YYYY")}