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?
LocalDateTime is an immutable date-time object that represents a date-time with default format as yyyy-MM-dd-HH-mm-ss.
parse(CharSequence text, DateTimeFormatter formatter) Return value: This method returns LocalTime which is the parsed local date-time. Exception: This method throws DateTimeParseException if the text cannot be parsed.
I'd suggest using java.time.format.DateTimeFormatter
.
First import it to JSP <%@ page import="java.time.format.DateTimeFormatter" %>
, then format variable ${localDateTime.format( DateTimeFormatter.ofPattern("dd.MM.yyyy"))}
.
Being new to java development, I'm interested wether this approach is acceptable in terms of 'best practice'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With