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 convertion exception.
<fmt:parseDate value="${date}" pattern="yyyy-MM-dd" var="parsedDate" type="date" />
Is there any tag or converter for LocalDateTime class in JSTL ?
It doesn't exist in the 14-year old JSTL.
Your best bet is creating a custom EL function. First create an utility method.
Then create a
/WEB-INF/functions.tld
wherein you register the utility method as an EL function:Finally use it as below:
Extend if necessary the method to take a
Locale
argument.No, It does not exist for LocalDateTime.
However, you can use:
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:
Check the repository for installation instructions: https://github.com/sargue/java-time-jsptags
Here is my solution (I'm using Spring MVC).
In the controller add a SimpleDateFormat with the LocalDateTime pattern as a model attribute:
Then use it in the JSP to parse the LocalDateTime and get a java.util.Date:
Now you can parse it with JSTL.