JSTL fmt:setTimeZone Formatting Tag

The JSTL Formatting Tag is used to set the specific time zone.
Syntax: 

fmt:setTimeZone tag attributes:

AttributeDescriptionRequired
valueIt specify the time zone to expose as a scoped or configuration variable.Yes
varIt specify the name of the variable to store the new time zone.No
scopeIt specify the scope of the variable to store the new time zone.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:setTimeZone JSTL formatting tag example</title>
 </head>
 <body>
       <c:set var="currentDate" value="<%=new java.util.Date()%>"/>
  <fmt:formatDate value="${currentDate}" type="both"/> <br/>
 
  Set Time Zone to HST<br/>
  <fmt:setTimeZone value="HST" />
  <fmt:formatDate value="${currentDate}" type="both"/>
 
 </body>
</html>
web.xml
<web-app>
 
  <welcome-file-list>
          <welcome-file>test.jsp</welcome-file>
  </welcome-file-list> 
 
</web-app>

Output:


No comments: