Wednesday, November 19, 2025
HomeLanguagesJavaTimeZone getDisplayName(boolean, int) Method in Java with Examples

TimeZone getDisplayName(boolean, int) Method in Java with Examples

The getDisplayName(boolean daylight, int style) method of TimeZone class in Java is used to get a particular name of this TimeZone that is easily understood by the user in the specified locale as passed by the user. The name is appropriate for presentation and display purpose.

Syntax:

public final String 
    getDisplayName(boolean daylight, 
                   int style)

Parameters: The method takes two parameters:

  • daylight: This is of boolean type and specifies if the value is true then it returns the daylight savings name else false.
  • style: This is either LONG or SHORT and refers to the style of display

Return Value: The method returns the display name of the TimeZone in the specified locale that is readable to the user.

Below programs illustrate the working of getDisplayName() Method of TimeZone:
Example 1:




// Java code to illustrate getDisplayName()
  
import java.util.*;
  
public class TimeZone_Demo {
    public static void main(String args[])
    {
  
        // Creating a time zone object
        TimeZone timezone = TimeZone.getDefault();
  
        // Getting a display name for the specified locale
        String display_name
            = timezone
                  .getDisplayName(true, 0);
  
        // Display name
        System.out.println("The Display name"
                           + " for the locale is: "
                           + display_name);
    }
}


Output:

The Display name for the locale is: UTC

Example 2:




// Java code to illustrate getDisplayName()
  
import java.util.*;
  
public class TimeZone_Demo {
    public static void main(String args[])
    {
  
        // Creating a time zone object
        TimeZone timezone
            = TimeZone
                  .getTimeZone(
                      "Asia/India");
  
        // Getting a display name for the specified locale
        String display_name
            = timezone
                  .getDisplayName(true, 1);
  
        // Display name
        System.out.println("The Display name"
                           + " for the locale is: "
                           + display_name);
    }
}


Output:

The Display name for the locale is: Greenwich Mean Time

Reference: https://docs.oracle.com/javase/7/docs/api/java/util/TimeZone.html#getDisplayName(boolean, %20int)

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32404 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6775 POSTS0 COMMENTS
Nicole Veronica
11924 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11994 POSTS0 COMMENTS
Shaida Kate Naidoo
6903 POSTS0 COMMENTS
Ted Musemwa
7159 POSTS0 COMMENTS
Thapelo Manthata
6859 POSTS0 COMMENTS
Umr Jansen
6846 POSTS0 COMMENTS