Calendar getDisplayName() Method in Java with Examples
The getDisplayName(int cal_field, int cal_style, Locale local) method of Calendar class is used to return the string representation of a calendar field(int cal_field) value in the given style(int cal_style) and locale(int local).
Syntax:
public String getDisplayName(int cal_field, int cal_style, Locale local)
Parameters: The method takes three parameters:
- cal_field: This is of integer type and refers to the field of the calendar on which the operation is to be performed.
- cal_style: This is of integer type and refers to the style that is supposed to be applied to the string representation.
- local: This is of Locale object type and refers to the locale representing the string.
Return Value: The method either returns the string representation of the given field in the form of the passing style else null if no string representation is available.
Below programs illustrate the working of getDisplayName() Method of Calendar class:
Example 1:
// Java Code to illustrate // getDisplayName() Method import java.util.*; public class Calendar_Demo_Locale { public static void main(String args[]) { // Creating Locale objects class Locale first_obj = new Locale("TURKISH", "Turkey"); Locale sec_obj = new Locale("ENGLISH", "UK"); // Displaying the objects System.out.println("First" + " object is : " + first_obj); System.out.println("Second" + " object is : " + sec_obj); // Getting the display names String obj_nm = first_obj.getDisplayName(); // Displaying the results System.out.println("Name of the" + " first object: " + obj_nm); // Getting the display names obj_nm = sec_obj.getDisplayName(); System.out.println("Name of the" + " second object: " + obj_nm); } } |
First object is : turkish_TURKEY Second object is : english_UK Name of the first object: turkish (TURKEY) Name of the second object: english (UK)
Example 2:
// Java Code to illustrate // getDisplayName() Method import java.util.*; public class Calendar_Demo_Locale { public static void main(String args[]) { // Creating Locale objects class Locale first_obj = new Locale("RUSSIAN", "Russia"); Locale sec_obj = new Locale("GERMAN", "Germany"); // Displaying the objects System.out.println("First" + " object is : " + first_obj); System.out.println("Second" + " object is : " + sec_obj); // Getting the display names String obj_nm = first_obj.getDisplayName(); // Displaying the results System.out.println("Name of the" + " first object: " + obj_nm); // Getting the display names obj_nm = sec_obj.getDisplayName(); System.out.println("Name of the" + " second object: " + obj_nm); } } |
First object is : russian_RUSSIA Second object is : german_GERMANY Name of the first object: russian (RUSSIA) Name of the second object: german (GERMANY)
Recommended Posts:
- TimeZone getDisplayName() Method in Java with Examples
- DayOfWeek getDisplayName() method in Java with Examples
- ZoneId getDisplayName() method in Java with Examples
- Locale getDisplayName() Method in Java with Examples
- ZoneOffset getDisplayName() method in Java with Examples
- TimeZone getDisplayName(boolean, int) Method in Java with Examples
- TimeZone getDisplayName(Locale locale) Method in Java with Examples
- Calendar get() method in Java with Examples
- Calendar set() Method in Java with Examples
- Calendar add() Method in Java with Examples
- Locale getDisplayName(Locale) Method in Java with Examples
- Calendar getTime() Method in Java with Examples
- Calendar isLenient() Method in Java with Examples
- Calendar internalGet() Method in Java with Examples
- Calendar getActualMinimum() Method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



