Es existiert nicht in der 14 Jahre alten JSTL.
Ihre beste Wette ist das Erstellen einer benutzerdefinierten EL-Funktion. Erstellen Sie zuerst eine Hilfsmethode.
package com.example;
public final class Dates {
private Dates() {}
public static String formatLocalDateTime(LocalDateTime localDateTime, String pattern) {
return localDateTime.format(DateTimeFormatter.ofPattern(pattern));
}
}
Erstellen Sie dann ein /WEB-INF/functions.tld
wobei Sie die Dienstprogramm Methode als eine EL-Funktion registrieren:
<?xml version="1.0" encoding="UTF-8" ?>
<taglib
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
version="2.1">
<tlib-version>1.0</tlib-version>
<short-name>Custom_Functions</short-name>
<uri>http://example.com/functions</uri>
<function>
<name>formatLocalDateTime</name>
<function-class>com.example.Dates</function-class>
<function-signature>java.lang.String formatLocalDateTime(java.time.LocalDateTime, java.lang.String)</function-signature>
</function>
</taglib>
es schließlich, wie unten verwenden:
<%@taglib uri="http://example.com/functions" prefix="f" %>
<p>Date is: ${f:formatLocalDateTime(date, 'dd.MM.yyyy')}</p>
verlängern, wenn notwendig, das Verfahren ein nehmen Locale
Argument.
Siehe auch: https://github.com/sargue/java-time-jsptags –