Format Timestamp type in Thymeleaf

  @GetMapping(value = "")
  public String init(Model m) {
    LocalDateTime ldt = LocalDateTime.now();
    Timestamp ts = Timestamp.valueOf(ldt);
    m.addAttribute("ts", ts); // ts = 2021-01-09 17:38:27.918333
    return "index";
  }
<p th:text="${#dates.format(new java.util.Date(ts), 'yyyy-MM-dd hh:mm')}"></p>
<!--output: 2021-01-09 17:38 -->

Recommended Posts

Format Timestamp type in Thymeleaf
Format XML in Java
Type determination in Java
Try functional type in Java! ①
Convert String type to Timestamp type
Input in tabular format with Struts2.5.x (JSP and Thymeleaf compatible)
Refer to enum in Thymeleaf
Precautions when using checkboxes in Thymeleaf
Draw screen with Thymeleaf in SpringBoot
Output JavaScript in Thymeleaf 3 without escaping
Is there no type in Ruby?
Tips for handling enums in thymeleaf
Thymeleaf usage notes in Spring Boot