springthymeleaf

Spring thymeleaf display month name from month number


I have an Integer for month in the DTO class. While displaying on thymeleaf template, I just want it to be month name in string like 'January' for integer value 0, and so on. I checked #dates but could not find one.


Solution

  • Shall use java.time.Month enumeration as below and convert case as you want. In this case I'm getting initcapped month name like January.

    th:text=${#strings.capitalize(#strings.toLowerCase(T(java.time.Month).of(dto.monthField+1).name))}