Get the ID of this timezone in Java



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: 
" + 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

Advertisements