Skip to content
Related Articles

Related Articles

Improve Article
ZoneOffset getDisplayName() method in Java with Examples
  • Last Updated : 13 Dec, 2018

The getDisplayName() method of the ZoneOffset class is 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:




// 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)
    {
  
        // Get the ZoneOffset instance
        ZoneOffset zoneOffset
            = ZoneOffset.of("+05:30");
  
        // get Zone id in style TextStyle.SHORT and
        // Locale = Locale.ENGLISH
        String response
            = zoneOffset.getDisplayName(TextStyle.SHORT,
                                        Locale.ENGLISH);
  
        // print result
        System.out.println("Display Name: "
                           + response);
    }
}
Output:
Display Name: +05:30

Program 2:




// 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)
    {
  
        // Get the ZoneOffset instance
        ZoneOffset zoneOffset
            = ZoneOffset.of("+05:30");
  
        // get Zone id in style TextStyle.FULL and
        // Locale = Locale.FRENCH
        String response = zoneOffset.getDisplayName(TextStyle.FULL,
                                                    Locale.FRENCH);
  
        // print result
        System.out.println("Display Name: "
                           + response);
    }
}
Output:
Display Name: +05:30

Reference: Oracle Doc

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 :