Close

Java Date Time - ZoneId.getDisplayName() Examples

Java Date Time Java Java API 


Class:

java.time.ZoneId

java.lang.Objectjava.lang.Objectjava.time.ZoneIdjava.time.ZoneIdjava.io.SerializableSerializableLogicBig

Method:

public String getDisplayName(TextStyle style,
                             Locale locale)

Returns the display name of the zone based on the provided style and locale.


Examples


package com.logicbig.example.zoneid;

import java.time.ZoneId;
import java.time.format.TextStyle;
import java.util.Locale;

public class GetDisplayNameExample {

public static void main(String... args) {
ZoneId z = ZoneId.of("America/New_York");
System.out.println(z);

for (TextStyle textStyle : TextStyle.values()) {
String s = z.getDisplayName(textStyle, Locale.getDefault());
System.out.printf("%18s > %s%n", textStyle, s);
}
}
}

Output

America/New_York
FULL > Eastern Time
FULL_STANDALONE > Eastern Time
SHORT > ET
SHORT_STANDALONE > ET
NARROW > America/New_York
NARROW_STANDALONE > ET




See Also