Dates & Times

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Dates & Times

bigal.nz
Hello,

I have a html form in springboot project which is displaying a date. The entity looks like:

    @DateTimeFormat(pattern="dd/MM/yyyy HH:mm")
    private Date commentDate;

The html looks like:

td th:text="${#dates.format(agencyComment.getCommentDate(), 'dd-MM-yy HH:mm')}"> /td><input type="hidden" th:value="${agencyComment?.commentDate}" th:name="plan.agencyComments[__${agencyCommentRow.index}__].commentDate"/>

However I get a validation error when I send the date & time back to the database.

Do I need a formatter or something along those lines?

Cheers

AG


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Dates & Times

danielfernandez
Administrator
Using @DateTimeFormat, formatting should happen automatically, but in order to be so at the Thymeleaf side you'd need to use th:field (which applies formatting automatically -- actually Spring MVC does) or if you need to use th:value/th:name specifically then you can use double-brace expressions, which should call the conversion artifacts in Spring: "${{....}}". More on this here: http://www.thymeleaf.org/doc/tutorials/3.0/thymeleafspring.html#the-conversion-service
Loading...