Java TimeZone - getDisplayName() Method
The java.util.TimeZone.getDisplayName() method returns a name in the specified style of this TimeZone suitable for presentation to the user in the specified locale. If the specified daylight is true, a Daylight Saving Time name is returned (even if this TimeZone doesn't observe Daylight Saving Time). Otherwise, a Standard Time name is returned.
Syntax
public String getDisplayName(boolean daylight, int style, Locale locale)
Parameters
daylight |
Specify true specifying a Daylight Saving Time name, or false specifying a Standard Time name. |
style |
Specify either LONG or SHORT. |
locale |
Specify the locale in which to supply the display name. |
Return Value
Returns the human-readable name of this time zone in the given locale.
Exception
- Throws IllegalArgumentException, if style is invalid.
- Throws NullPointerException, if locale is null.
Example:
In the example below, the java.util.TimeZone.getDisplayName() method is used to get a name of the given time zone.
import java.util.*; public class MyClass { public static void main(String[] args) { //creating a TimeZone object TimeZone tz = TimeZone.getTimeZone("IST"); //creating a locale Locale loc = Locale.GERMANY; //get the display name of the TimeZone object Object tzname = tz.getDisplayName(true, 1, loc); //printing the display name System.out.println("Display name is: " + tzname); } }
The output of the above code will be:
Display name is: Indische Sommerzeit
❮ Java.util - TimeZone