English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The <fmt:parseDate> tag is used to parse dates.
<fmt:parseDate value="<string>" type="<string>" dateStyle="<string>" timeStyle="<string>" pattern="<string>" timeZone="<string>" parseLocale="<string>" var="<string>" scope="<string>"/>
The <fmt:parseDate> tag has the following attributes:
attribute | description | necessary | default value |
---|---|---|---|
value | date to be displayed | 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 | time zone for displaying date | No | default timezone |
var | Store the variable name for formatting the date | No | Display on the page |
Scope | Store the scope of the formatted log variable | No | Page |
Set the time format of the output we need.
<%@ 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 Tag</title> </head> <body> <h2>Date Parsing:</h2> <c:set var="now" value="20-10-2015" /> <fmt:parseDate value="${now}" var="parsedEmpDate" pattern="dd"-MM-yyyy" /> <p>The parsed date is: <c:out value="${parsedEmpDate}" /></p> </body> </html>
The above example runs as follows:
Date Parsing: The parsed date is: Tue Oct 20 00:00:00 CST 2015