We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Does Your Timezone Support Daylight Saving Time?

Submitted by: M S Sridhar(sridhar.ms@gmail.com)

Friday Apr 13th 2018 by M S Sridhar

Language: Java, Expertise: Intermediate - Figure out whether or not your timezone supports Daylight Saving Time programmatically.

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();
   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());
Mobile Site | Full Site
Copyright 2018 © QuinStreet Inc. All Rights Reserved