Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 745
Ugur Artun Avatar asked Feb 24 '16 15:02

Ugur Artun


People also ask

What is the format for LocalDateTime?

LocalDateTime is an immutable date-time object that represents a date-time with default format as yyyy-MM-dd-HH-mm-ss.

How do I parse LocalDateTime?

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.


1 Answers

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'.

like image 158
Alexandr Tsyganok Avatar answered Sep 21 '22 21:09

Alexandr Tsyganok