Java Utility Library

Java TimeZone - getDisplayName() Method



The java.util.TimeZone.getDisplayName() method returns a name in the specified style of this TimeZone suitable for presentation to the user in the default locale. If the specified daylight is true, a Daylight Saving Time name is returned (even if this TimeZone doesn't observe Daylight Saving Time). Otherwise, a Standard Time name is returned.

Syntax

public final String getDisplayName(boolean daylight,
                                   int style)

Parameters

daylight Specify true specifying a Daylight Saving Time name, or false specifying a Standard Time name.
style Specify either LONG or SHORT.

Return Value

Returns the human-readable name of this time zone in the default locale.

Exception

Throws IllegalArgumentException, if style is invalid.

Example:

In the example below, the java.util.TimeZone.getDisplayName() method is used to get a name of the given time zone.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating a TimeZone object
    TimeZone tz = TimeZone.getTimeZone("IST");
   
    //get the display name of the TimeZone object
    Object tzname = tz.getDisplayName(true, 1);

    //printing the display name
    System.out.println("Display name is: " + tzname);
  }
}

The output of the above code will be:

Display name is: India Daylight Time

❮ Java.util - TimeZone