Get the ID of this timezone in Java

Java 8Object Oriented ProgrammingProgramming

In order to get the ID of this timezone in Java, we use the getDisplayName() method. The getDisplayName() returns a name of this time zone acceptable for display to the user in the default locale. In other words, the name returned by the getDisplayName() is user friendly.

Declaration − The java.util.TimeZone.getDisplayName() is declared as follows −

public final String getDisplayName()

Let us see a program to get the ID of this timezone in Java −

Example

 Live Demo

import java.util.*;
public class Example {
   public static void main( String args[] ) {
      // creating default object of TimeZone
      TimeZone obj = TimeZone.getDefault();
      System.out.println("Default timezone object: \n" + obj);
      // getting the default name which is readable by the user
      String name = obj.getDisplayName();
      System.out.println("Display name of this timezone: " + name);
   }
}

Output

Default timezone object: sun.util.calendar.ZoneInfo[id="Etc/UTC",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]
Display name of this timezone: Coordinated Universal Time
raja
Published on 08-Jan-2019 07:44:05
Advertisements