0

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

agusgambina
  • 6,229
  • 14
  • 54
  • 94
  • i think exception states clearly that you are passing "2015-12-10T00:00:00.000Z" where date in format "dd-MM-YYYY" is expected and this happens because you use `toString`. What is the type of `user.birthday`? If you want to change date into formated string then try using `toString` overloaded method of `DateTime` that takes format as argument. `DateTimeFormat` seems to have `print` method as well that takes date. – Łukasz Jan 08 '16 at 19:30
  • Thank you @Łukasz the user.birthday is DateTime type (from nscala-time library). – agusgambina Jan 08 '16 at 19:35
  • Then any of following methods should work. You can check joda time api instead of nscala it should be similar. Let your ide tell you what methods you have and use the one that suits your need. – Łukasz Jan 08 '16 at 19:38

1 Answers1

0

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")}
James
  • 2,756
  • 17
  • 19