Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

TimeZone getDisplayName(Locale locale) Method in Java with Examples

  • Last Updated : 31 Jan, 2019
Geek Week

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)

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :