Taglib displays Java time. Localdate format
I want to display the formatted Java. JSP in my JSP time. LocalDate. Do you know any taglib for this?
For Java util. Date, we use <% @ taglib prefix = "FMT" URI=“ http://java.sun.com/jstl/fmt ”%>. Is there anything like Java time. What is the content of localdate?
Solution
Afsun's tips inspired me to create a quick solution
>Create directory tags under / web-inf. > Create the tag file localdate. In the tags directory tag. > Place the bellows code in this tag file:
<%@ tag body-content="empty" pageEncoding="UTF-8" trimDirectiveWhitespaces="true" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ attribute name="date" required="true" type="java.time.LocalDate" %> <%@ attribute name="pattern" required="false" type="java.lang.String" %> <c:if test="${empty pattern}"> <c:set var="pattern" value="MM/dd/yyyy"/> </c:if> <fmt:parseDate value="${date}" pattern="yyyy-MM-dd" var="parsedDate" type="date"/> <fmt:formatDate value="${parsedDate}" type="date" pattern="${pattern}"/>
>Go to where you want to display Java time. JSP file for localdate
4.1. Add taglib directive <% @ taglib prefix = "tags" tagdir = "/ WEB-INF / tags"% > at the top of the file
4.2. Use the localdate tag as follows:
>< tags:localDate date =“${yourDateToPrint}”/>>< tags:localDate date =“${yourDateToPrint}”pattern =“${yourPatternFormat}”/>