Javatpoint Logo
Javatpoint Logo

Java Calendar getDisplayName() Method //return String

The getDisplayName() method of java.util.Calendar class returns String representation of the calendar field value passed as parameter in a given style and local. Style and local are also passed as parameter. If no String representation is available, getDisplayName() returns null value. If String representation is available, get() method is called to access the calendar field value.

Syntax

Parameter

field - the calendar fields are passed like MONTH , DAY_OF_WEEK etc

style - it is the style to be applied to String representation of field passed as parameter.

locale - the locale for the string representation.

Returns

The string representation of field passed as parameter in specified format (style) and local is returned.

Throws

IllegalArgumentExeption

NullPointerException

Example 1

Test it Now

Output:

Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday 

Example 2

Test it Now

Output:

Days of week are
January
February
March
April
May
June
July
August
September
October
November
December
Months of year are
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday

Example 3

Test it Now

Output:

Days of year do not have String representation
null
null
null
null
null
null
null

Java Calendar getDisplayName(int field, int style, Locale locale) Method

The getDisplayName() method of java.util.Calendar class returns Map representation of the calendar field value passed as parameter in a given style and local. Style and local are also passed as parameter. As this method returns Map representation of passed field it has a String representation and a key value in integer form. Key value is used to uniquely identify.

Syntax

Parameter

field - the calendar fields are passed like MONTH , DAY_OF_WEEK etc

style - it is the style to be applied to String representation of field passed as parameter.

locale - the locale for the string representation.

Returns

The Map representation of field passed as parameter in specified format (style) and local is returned. Local and style is also passed as parameter.

Throws

IllegalArgumentExeption

NullPointerException

Example 1

Test it Now

Output:

List of Days in a week are :
{Friday=6, Monday=2, Saturday=7, Sunday=1, Thursday=5, Tuesday=3, Wednesday=4}

Example 2

Test it Now

Output:

List of Months are :
{April=3, August=7, December=11, February=1, January=0, July=6, June=5, March=2, May=4, November=10, October=9, September=8}



Please Share

facebook twitter google plus pinterest