Open In App

JSTL Formatting <fmt:setTimeZone> Tag

In JSTL applications, we can use the <fmt:setTimeZone> tag to set the time zone for date and time formatting. Using this tag we can specify a particular time zone for displaying the dates and times. In this article, we will discuss the Syntax and the parameters of this tag. We will also see its additional attributes table and the example demonstrating the implementation.

Syntax <fmt:setTimeZone> Tag

<fmt:setTimeZone value="timeZoneId" 
var="resultVar"
scope="page|request|session|application
"/>

Parameters



Attributes of JSTL <fmt:setTimeZone> Tag

The table describes attributes present in <fmt:setTimeZone> tag with proper description.

Attribute

Description

Required

Default

value

This is used to set the time zone identifier.

Yes

None

var

This is used to store the time zone result.

No

None

scope

This is used to set the scope of variables as page, request, session, and application.

No

page

Example of JSTL Formatting <fmt:setTimeZone> Tag

In this example, we will discuss how to create any date and time format using JSTL tag <fmt:setTimeZone>.






<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
    
<html>
  <head>
      <title>fmt:setTimeZone Tag</title>
  </head>
  <body>
    <fmt:setTimeZone value="America/New_York" />
    <h2>Date and Time Example</h2>
    <p>Current Date and Time: <fmt:formatDate value="${now}" pattern="yyyy-MM-dd HH:mm:ss" /></p>
  </body>
</html>

Output:

Explanation of the above Program:


Article Tags :