JSTL Format fmt:parseDate Tag

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

<fmt: parseDate attributes/>

Attributes Of <fmt: parseDate> Tag

AttributesDescription
valueSpecifies date or time to be parsed.
typeSpecifies the string date, time or both to be parsed.
dateStyleSpecifies the style of date to be parse that is short, long or medium .
patternSpecifies the custom pattern that how the date or time to be parsed..
varSpecifies the variable name to which the parsed date and time has to be stored.
scopeThe Scope into which the variable date and time are defined in “var” attribute.
timeStyleSpecifies how the style of time has to be parsed that is short, long or medium.
timeZoneUsed to set the formatted date or time.
parseLocaleSpecifies the locale to parse the date or time.

Example

<%@ 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>

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 :
jstl_fmt parseDate tag output_demo

 

Previous Tutorial : JSTL Format fmt:formatDate Tag :: Next Tutorial : JSTL Format fmt:setLocale Tag

Comments

comments

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Speak Your Mind

*