Open In App

TimeZone getDisplayName(Locale locale) Method in Java with Examples

Improve
Improve
Like Article
Like
Save
Share
Report

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:




// 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);
    }
}


Output:

The Display name for the locale is: Greenwich Mean Time

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("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);
    }
}


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)



Last Updated : 31 Jan, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads