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:

AttributeDescriptionRequired
valueIt specify the date value to display.Yes
typeDATE, TIME, or BOTHNo
dateStyleFULL, LONG, MEDIUM, SHORT, DEFAULT.No
timeStyleFULL, LONG, MEDIUM, SHORT, DEFAULT.No
patternIt specify the custom formatting pattern.No
timeZoneIt specify the time zone of the displayed date.No
varIt specify the name of the variable to store the formatted date.No
scopeIt 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.

 

Content Protection by DMCA.com
Please Share