Search code examples
jspjstldate-formatjava-time

JSTL LocalDateTime format


I want to format my Java 8 LocalDateTime object in "dd.MM.yyyy" pattern. Is there any library to format? I tried code below but got conversion exception.

<fmt:parseDate value="${date}" pattern="yyyy-MM-dd" var="parsedDate" type="date" />

Is there any tag or converter for LocalDateTime class in JSTL?


Solution

  • Actually I had the same problem and ended up forking the original Joda Time jsp tags to create Java 8 java.time JSP tags.

    With that library your example would be something like this:

    <javatime:parseLocalDateTime value="${date}" pattern="yyyy-MM-dd" var="parsedDate" />
    

    Check the repository for installation instructions: https://github.com/sargue/java-time-jsptags