The java.util.TimeZone
class represents a time zone offset and also figures out daylight saving time adjustments. It is used in conjunction with Calendar
, Date
, and the formatting classes.
Commonly Used Methods

Common Time Zone IDs Examples
"UTC"
"GMT"
"Asia/Kolkata"
"America/New_York"
"Europe/London"
For More Time Zone ID’s
https://docs.oracle.com/middleware/1221/wcs/tag-ref/MISC/TimeZones.html
Simple Example
import java.util.TimeZone; public class TimeZoneExample { public static void main(String[] args) { TimeZone tz = TimeZone.getTimeZone("Asia/Kolkata"); System.out.println("ID: " + tz.getID()); System.out.println("Raw Offset (ms): " + tz.getRawOffset()); System.out.println("Uses DST: " + tz.useDaylightTime()); } }
Problem Statement:Listing All TimeZones with GMT Offset
LotusJavaPrince and Mahesh are developing a global banking application. They need to show all supported time zones and their GMT offsets to let users pick their preferred region during account creation.
import java.util.TimeZone; import java.util.Date; import java.text.SimpleDateFormat; public class TimeZoneCaseStudy { public static void main(String[] args) { String[] zoneIds = TimeZone.getAvailableIDs(); Date now = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); System.out.printf("%-35s %-10s %-15s\n", "Time Zone ID", "GMT Offset", "Current Time"); System.out.println("--------------------------------------------------------------"); for (String id : zoneIds) { TimeZone tz = TimeZone.getTimeZone(id); int offsetInMillis = tz.getRawOffset(); int hours = offsetInMillis / (1000 * 60 * 60); int minutes = Math.abs((offsetInMillis / (1000 * 60)) % 60); String offset = String.format("GMT%+03d:%02d", hours, minutes); sdf.setTimeZone(tz); String currentTime = sdf.format(now); System.out.printf("%-35s %-10s %-15s\n", id, offset, currentTime); } } }
Time Zone ID GMT Offset Current Time
--------------------------------------------------------------
Asia/Kolkata GMT+05:30 21:47:12
America/New_York GMT-04:00 12:17:12
Europe/London GMT+01:00 17:47:12
...
...
The java.util.TimeZone
class is essential for managing regional time settings in applications that support international users. With its powerful methods to manipulate time zone information, it works seamlessly with classes like Calendar
, Date
, and SimpleDateFormat
.
By understanding methods like getTimeZone()
, getRawOffset()
, and useDaylightTime()
, developers can build globally aware applications with accurate time management.