<fmt:parseDate> Tag
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:
| Attribute | Description | Required | Default Value |
|---|---|---|---|
| value | The date to display | Yes | None |
| type | DATE, TIME, or BOTH | no | date |
| dateStyle | FULL, LONG, MEDIUM, SHORT, or DEFAULT | no | default |
| timeStyle | FULL, LONG, MEDIUM, SHORT, or DEFAULT | no | default |
| pattern | Custom format pattern | no | None |
| timeZone | The time zone for displaying the date | no | Default time zone |
| var | The variable name for storing the formatted date | no | Displayed on the page |
| scope | The scope for storing the formatted date variable | no | Page |
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
Other extensions
JSP Standard Tag Library