Java.util.Calendar.getDisplayName() Method

Advertisements


Description

The java.util.Calendar.getDisplayName() method returns the string representation of the calendar field value in the given style and locale.

Declaration

Following is the declaration for java.util.Calendar.getDisplayName() method

public String getDisplayName(int field,int style,Locale locale)

Parameters

  • field -- the calendar field.

  • style -- the style that will be applied to the string representation

  • locale -- the string representation locale

Return Value

The method returns the string representation of the given field in the given style, or null if no string representation is available.

Exception

  • IllegalArgumentException - if field or style are invalid, or if this Calendar is non-lenient and any of the fields has invalid values

  • NullPointerException - if locale is null

Example

The following example shows the usage of java.util.calendar.getDisplayName() method.

package com.tutorialspoint;

import java.util.*;

class CalendarGetDisplayNameEx {

   public static void main(String args[]) {

      // create objects of locale class
      Locale object1 = new Locale("GERMAN", "Germany");
      Locale object2 = new Locale("FRENCH", "France");
      System.out.println("Object1 is : " + object1);
      System.out.println("Object2 is : " + object2);

      // get the display name for object1
      String objName = object1.getDisplayName();

      // print the results
      System.out.println("Name for object1 : " + objName);
	  
      // get the display name for object2
      objName = object2.getDisplayName();
      System.out.println("Name for object2 : " + objName);
   }
}

Let us compile and run the above program, this will produce the following result:

Object1 is : german_GERMANY
Object2 is : french_FRANCE
Name for object1 : german (GERMANY)
Name for object2 : french (FRANCE)



Advertisements
Advertisements