0

I have date and time saved in database using timestamp format, so it looks like this: 2022-03-18 14:15:09.011. Also in class WoundedPerson I have this: @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date addAt; and create date using function new Date().

I try to get date and time of specific person from database to website using Thymeleaf. So I get data of person: <input type="hidden" name="addAt" th:value="${woundedPerson.getAddAt()}">

Then I processed it in controller adding to model and add to website using <h3 th:text="${woundedPerson.getAddAt()}"></h3>

But on website show something like this format: Mon Mar 14 22:29:58 CET 2022, but I want a format look like in a database or something like that. It means that I want only date and time, not name of day and CET.

How can I do that?

Natalia
  • 17
  • 2

1 Answers1

0

Use #temporals in Thymeleaf like that:

<h3 th:text="${#temporals.format(woundedPerson.getAddAt(), 'yyyy-MM-dd HH:mm:ss')}"></h3>
Krishna Majgaonkar
  • 1,532
  • 14
  • 25
Ruslan
  • 11
  • 4