<fmt:parseDate> Tag

JSP 标准标签库JSP Standard Tag Library

The <fmt:parseDate> tag is used to parse dates.

Syntax

<fmt:parseDate
   value="<string>"
   type="<string>"
   dateStyle="<string>"
   timeStyle="<string>"
   pattern="<string>"
   timeZone="<string>"
   parseLocale="<string>"
   var="<string>"
   scope="<string>"/>

Attributes

The <fmt:parseDate> tag has the following attributes:

AttributeDescriptionRequiredDefault Value
valueThe date to displayYesNone
typeDATE, TIME, or BOTHnodate
dateStyleFULL, LONG, MEDIUM, SHORT, or DEFAULTnodefault
timeStyleFULL, LONG, MEDIUM, SHORT, or DEFAULTnodefault
patternCustom format patternnoNone
timeZoneThe time zone for displaying the datenoDefault time zone
varThe variable name for storing the formatted datenoDisplayed on the page
scopeThe scope for storing the formatted date variablenoPage

The attribute sets the time format we need for output.



Example Demonstration

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<html>
<head>
  <title>JSTL fmt:parseDate 标签</title>
</head>
<body>
<h3>日期解析:</h3>
<c:set var="now" value="20-10-2015" />

<fmt:parseDate value="${now}" var="parsedEmpDate" 
                              pattern="dd-MM-yyyy" />
<p>解析后的日期为: <c:out value="${parsedEmpDate}" /></p>

</body>
</html>

The result of the above example:

日期解析:

解析后的日期为: Tue Oct 20 00:00:00 CST 2015

JSP 标准标签库JSP Standard Tag Library

Other extensions