TimeZone getDisplayName(Locale locale) Method in Java with Examples

The getDisplayName(Locale locale_time) 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(Locale locale_time)

Parameters: The method takes one parameter locale_time of Locale object type and refers to the locale into which the display name is to be supplied.



Return Value: The method returns the display name of the TimeZone in the specified locale.

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

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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");
  
        // Creating the locale
        Locale locale
            = new Locale("ENGLISH",
                         "USA");
  
        // Getting a display name for specified locale
        String display_name
            = timezone
                  .getDisplayName(locale);
  
        // Display name
        System.out.println("The Display name"
                           + " for the locale is: "
                           + display_name);
    }
}

chevron_right


Output:

The Display name for the locale is: Greenwich Mean Time

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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("Australia/Sydney");
  
        // Creating the locale
        Locale locale = new Locale("ENGLISH",
                                   "Australia");
  
        // Getting a display name
        // for specified locale
        String display_name
            = timezone
                  .getDisplayName(locale);
  
        // Display name
        System.out.println("The Display name"
                           + " for the locale is: "
                           + display_name);
    }
}

chevron_right


Output:

The Display name for the locale is: 
Australian Eastern Standard Time (New South Wales)

Reference: https://docs.oracle.com/javase/7/docs/api/java/util/TimeZone.html#getDisplayName(java.util.Locale)



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.