Java TimeZone getDisplayName() Example
TimeZone class getDisplayName() method example. This example shows you how to use getDisplayName() method.
Syntax is : public String getDisplayName(boolean daylight, int style, Locale locale)
Method returns a name of this time zone suitable for presentation to the user in the specified locale. If the display name is not available for the locale, then this method returns a string in the normalized custom ID format.
Here is the code.
/**
* @(#) GetDisplayName2TimeZone.java
* A class representing use of method getDisplayName() of TimeZone
class in java.util Package.
* @Version 27-May-2008
* @author Rose India Team
*/
import java.util.*;
class GetDisplayName2TimeZone {
public static void main( String args[] ){
// Create object of TimeZone class.
TimeZone obj = TimeZone.getTimeZone("Europe/Paris");
// Create object of Locale class.
Locale locale = new Locale("ENGLISH" , "CHINA");
// getDisplayName() method call with short style.
String name = obj.getDisplayName(true, obj.SHORT, locale);
System.out.println("Name of time zone using short style : " + name);
// getDisplayName() method call with long style.
name = obj.getDisplayName(true, obj.LONG, locale);
System.out.println("Name of time zone using long style : " + name);
}
} |
Output of the program.
Name of time zone using short style : CEST
Name of time zone using long style : Central European Summer Time |
|