dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Java
Expertise: Intermediate
Apr 13, 2018

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


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());
   }
}
M S Sridhar
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date