JavaBeat

  • Home
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Privacy
  • Contact Us

JSTL Format fmt:parseDate Tag

February 22, 2014 by Krishna Srinivasan Leave a Comment

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

 

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

Filed Under: Java EE Tagged With: JSTL Tutorials

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.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Follow Us

  • Facebook
  • Pinterest

As a participant in the Amazon Services LLC Associates Program, this site may earn from qualifying purchases. We may also earn commissions on purchases from other retail websites.

JavaBeat

FEATURED TUTORIALS

Answered: Using Java to Convert Int to String

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Copyright © by JavaBeat · All rights reserved