The <fmt: parseDate> tag is used to parse and format the date and time according to the customized formatting pattern.
Syntax Of <fmt: parseDate> Tag
[code lang=”html”]
<fmt: parseDate attributes/>
[/code]
Attributes Of <fmt: parseDate> Tag
Attributes | Description |
---|---|
value | Specifies date or time to be parsed. |
type | Specifies the string date, time or both to be parsed. |
dateStyle | Specifies the style of date to be parse that is short, long or medium . |
pattern | Specifies the custom pattern that how the date or time to be parsed.. |
var | Specifies the variable name to which the parsed date and time has to be stored. |
scope | The Scope into which the variable date and time are defined in “var” attribute. |
timeStyle | Specifies how the style of time has to be parsed that is short, long or medium. |
timeZone | Used to set the formatted date or time. |
parseLocale | Specifies the locale to parse the date or time. |
Example
[code lang=”html”]
<%@ 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"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>ParseDate Tag</title>
</head>
<body>
<h2>Parse Date</h2>
<c:set var="today" value="12-02-2014" />
<fmt:parseDate value="${today}" pattern="dd-MM-yyyy" var="parseDate" />
<c:out value="${parseDate}"></c:out>
</body>
</html>
[/code]
Details of the Code
- <fmt:parseDate value=”${today}” pattern=”dd-MM-yyyy” var=”parseDate”/>tag is used to parse the date by using the attribute value, pattern and var.
- Pattern= “dd-MM-yyyy” is used to show how the date format to be displayed.
Steps for Execution
- Save this file as example.jsp in your eclipse IDE.
- Now select this jsp file, right mouse click and select Run as ->Run on server
Output
When the execution process is completed successfully we will get the following output :
Previous Tutorial : JSTL Format fmt:formatDate Tag :: Next Tutorial : JSTL Format fmt:setLocale Tag
Leave a Reply