我想在JSP中显示格式化的java.time.LocalDate
。你知道用于此的任何taglib吗?
对于java.util.Date
我们使用<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
。是否存在类似于java.time.LocalDate
的内容?
答案 0 :(得分:10)
Afsun的提示激励我创建一个快速的解决方案。
/WEB-INF
创建目录tags
下。localDate.tag
目录中创建标记文件tags
。将波纹管代码放入此标记文件中:
<%@ 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}"/>
转到要在其中显示java.time.LocalDate
。
4.1。在文件顶部添加taglib指令<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
。
4.2。使用localDate
标记,如下所示:
<tags:localDate date="${yourDateToPrint}"/>
<tags:localDate date="${yourDateToPrint}" pattern="${yourPatternFormat}"/>
答案 1 :(得分:2)
您可以fmt:parseDate
执行此操作。请尝试以下操作:
<fmt:parseDate value="${dateForParsing}" pattern="yyyy-MM-dd" var="parsedDate" type="date" />
<fmt:formatDate value="${parsedDate}" var="newParsedDate" type="date" pattern="dd.MM.yyyy" />
我希望这可以帮到你。More information
答案 2 :(得分:0)
一种解决方案是在Javabean上使用@XmlJavaTypeAdapter(LocalDateAdapter.class)批注:
[[layout.utility_menu]]
[[layout.systems_lister]]
[[layout.get_started_homepage_lister]]
[[page.Footer]]