Related Articles

Related Articles

ZoneId getDisplayName() method in Java with Examples
  • Last Updated : 07 May, 2019

The getDisplayName() method of the ZoneId class used to get the textual representation of the zone suitable for presentation to the user such as ‘British Time’ or ‘+02:00’.If no textual mapping is found then the full ID is returned.

Syntax:

public String getDisplayName(TextStyle style, Locale locale)

Parameters: This method accepts two parameters style and locale where style represents the length of the text required and locale represents the locale to use.

Return value: This method returns the text value of the zone.

Below programs illustrate the getDisplayName() method:



Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate
// ZoneId.getDisplayName() method
  
import java.time.*;
import java.time.format.TextStyle;
import java.util.Locale;
  
public class GFG {
    public static void main(String[] args)
    {
        // create ZoneId object
        ZoneId zoneId
            = ZoneId.of("Europe/Paris");
  
        // get Zone id in style TextStyle.SHORT and
        // Locale = Locale.ENGLISH
        String response = zoneId.getDisplayName(TextStyle.SHORT, Locale.ENGLISH);
  
        // print result
        System.out.println("ZoneId:"
                           + response);
    }
}

chevron_right


Output:

ZoneId:CET

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate
// ZoneId.getDisplayName() method
  
import java.time.*;
import java.time.format.TextStyle;
import java.util.Locale;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create ZoneId object
        ZoneId zoneId
            = ZoneId.of("Asia/Calcutta");
  
        // get Zone id in style TextStyle.FULL and
        // Locale = Locale.FRENCH
        String response = zoneId.getDisplayName(TextStyle.FULL,
                                                Locale.FRENCH);
  
        // print result
        System.out.println("ZoneId: "
                           + response);
    }
}

chevron_right


Output:

ZoneId: Inde

Reference: https://docs.oracle.com/javase/10/docs/api/java/time/ZoneId.html#getDisplayName(java.time.format.TextStyle, 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.




My Personal Notes arrow_drop_up
Recommended Articles
Page :