JSTL Core <fmt:parseDate> Tag

Advertisements


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

Attribute:

The <fmt:parseDate> tag has following attributes:

AttributeDescription RequiredDefault
valueDate value to read (parse)NoBody
typeDATE, TIME, or BOTHNodate
dateStyleFULL, LONG, MEDIUM, SHORT, or DEFAULTNoDefault
timeStyleFULL, LONG, MEDIUM, SHORT, or DEFAULTNoDefault
parseLocaleLocale to use when parsing the dateNoDefault locale
patternCustom parsing patternNoNone
timeZoneTime zone of the parsed dateNoDefault time zone
varName of the variable to store the parsed dateNoPrint to page
scopeScope of the variable to store the formatted dateNopage

A pattern attribute is provided that works just like the pattern attribute for the <fmt:formatDate> tag. However, in the case of parsing, the pattern attribute tells the parser what format to expect.

Example:

<%@ 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>
<h3>Date Parsing:</h3>
<c:set var="now" value="20-10-2010" />

<fmt:parseDate value="${now}" var="parsedEmpDate" 
                              pattern="dd-MM-yyyy" />
<p>Parsed Date: <c:out value="${parsedEmpDate}" /></p>

</body>
</html>

This would produce following result:

Date Parsing:

Parsed Date: Wed Oct 20 00:00:00 GST 2010



Advertisements
Advertisements