<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<fmt:formatDate var="articleDate" value="${article.adate }" pattern="MM-dd"/>${articleDate }
<fmt:parseDate value="${param.date}" var="date" pattern="yyyy/MM/dd:HH:mm:ss>
<fmt:parseDate value="${param.isoDate}" var="isoDate" pattern="yyyyMMdd'T'HHmmss">
The input parameters must match the patterns, or the JSP will thrown an exception. This page does no error handling.
Input parameters:
Date:
isoDate: 20040531T235959
Dates
Tag Output
Attribute: value; required. Tag has no body.
<fmt:formatDate value="${date}" type="both"/>
<fmt:formatDate value="${isoDate}" type="both"/>
Attribute: type; optional. Indicates what to print: date, time, or both.
<fmt:formatDate value="${date}" type="date"/>
<fmt:formatDate value="${isoDate}" type="time"/>
Attribute: dateStyle; optional. Varies the date format.
<fmt:formatDate value="${isoDate}" type="date" dateStyle="default"/>
<fmt:formatDate value="${isoDate}" type="date" dateStyle="short"/>
<fmt:formatDate value="${isoDate}" type="date" dateStyle="medium"/>
<fmt:formatDate value="${isoDate}" type="date" dateStyle="long"/>
<fmt:formatDate value="${isoDate}" type="date" dateStyle="full"/>
Attribute: timeStyle; optional. Varies the time format.
<fmt:formatDate value="${isoDate}" type="time" timeStyle="default"/>
23:59:59
<fmt:formatDate value="${isoDate}" type="time" timeStyle="short"/>
下午11:59
<fmt:formatDate value="${isoDate}" type="time" timeStyle="medium"/>
23:59:59
<fmt:formatDate value="${isoDate}" type="time" timeStyle="long"/>
<fmt:formatDate value="${isoDate}" type="time" timeStyle="full"/>
下午11时59分59秒 CDT
<fmt:formatDate value="${isoDate}" pattern= "MM/dd/yyyy HH:mm aa" type="time" timeStyle="full"/></p>
Attribute: pattern; optional. Inidcates date/time custom patterns.
<fmt:formatDate value="${date}" type="both" pattern="EEEE, MMMM d, yyyy HH:mm:ss Z"/>
<fmt:formatDate value="${isoDate}" type="both" pattern="d MMM yy, h:m:s a zzzz/>
得到当前时间:
<jsp:useBean id="now" class="java.util.Date" />
调用的方法
<fmt:formatDate value="${now}" type="both" dateStyle="long" pattern="yyyy-MM-dd" />