JSTL fmt:formatDate Formatting Tag

The JSTL <fmt:formatDate> Formatting Tag is used for formatting the dates.

Syntax:<fmt:formatDate value=”val” otherattributes />

fmt:formatDate tag attributes:

Attribute Description Required
value It specify the date value to display. Yes
type DATE, TIME, or BOTH No
dateStyle FULL, LONG, MEDIUM, SHORT, DEFAULT. No
timeStyle FULL, LONG, MEDIUM, SHORT, DEFAULT. No
pattern It specify the custom formatting pattern. No
timeZone It specify the time zone of the displayed date. No
var It specify the name of the variable to store the formatted date. No
scope It specify the scope of the variable to store the formatted date. No

Example:

test.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
 
<html>
	<head>
		<title>fmt:formatDate JSTL formatting tag example</title>
	</head>
	<body>
	  <c:set var="currentDate" value="<%=new java.util.Date()%>"/>
	  Current date after setting type attribute to date: <br/>
	  <fmt:formatDate type="date" value="${currentDate}" /> <br/>
	  Current date after setting type attribute to time: <br/>
	  <fmt:formatDate type="time" value="${currentDate}" /><br/>
	  Current date after setting type attribute to both: <br/>
	  <fmt:formatDate type="both" value="${currentDate}" /> <br/>
	  Current date after setting pattern attribute: <br/>
	  <fmt:formatDate pattern="yyyy-MM-dd" value="${currentDate}"/>
	</body>
</html>

web.xml

<web-app>
 
  <welcome-file-list>
          <welcome-file>test.jsp</welcome-file>
  </welcome-file-list>	
 
</web-app>

Output:

jsp example 45
 
Download this example.
 
Next Topic: JSTL fmt:parseDate Formatting Tag with example.
Previous Topic: JSTL fmt:parseNumber Formatting Tag with example.

Related Topics:

JSTL fmt:formatNumber Formatting Tag with example.
JSTL fmt:parseNumber Formatting Tag with example.
JSTL fmt:formatDate Formatting Tag with example.
JSTL fmt:parseDate Formatting Tag with example.
JSTL fmt:bundle Formatting Tag with example.
JSTL fmt:setBundle Formatting Tag with example.
JSTL fmt:setLocale Formatting Tag with example.
JSTL fmt:timeZone Formatting Tag with example.
JSTL fmt:setTimeZone Formatting Tag with example.
JSTL fmt:requestEncoding Formatting Tag with example.