Does Your Timezone Support Daylight Saving Time?

Does Your Timezone Support Daylight Saving Time?

You may want to know if your timezone supports Daylight Saving Time programmatically. This can be easily determined with the code below:

Listing 1. Sample Code

import java.util.TimeZone;public class DaylightSavingsTime{      public static void main(String args[])   {      DaylightSavingsTime daylightSavingsTime = new DaylightSavingsTime();      daylightSavingsTime.proceed();   }      private void proceed()   {      TimeZone tz = TimeZone.getDefault();      //Uncomment the below line to use the timezone of your choice. Repalce "America/Los_Angeles" with your timezone id.      //TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");      //This returns the ID of the time zone used      System.out.println("tz.getID(): " + tz.getID());      //The display name of the ID      System.out.println("tz.getDisplayName(): " + tz.getDisplayName());      //This returns true if the time zone uses Daylight Savings Time      System.out.println("tz.getDSTSavings(): " + tz.getDSTSavings());      //This returns true if the time zone is currently using Daylight Savings Time      System.out.println("tz.useDaylightTime(): " + tz.useDaylightTime());   }}

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist