Calendar.getDisplayName(field, style, local) String output of input field of Calendar object .

field : Name of the field for which string we want to return, like Calendar.MONTH
style : Style to use , LONG or SHORT
Locale : The local of string representation.

Returns the string of the calendar' field .

Note that we have added these utilities
import java.util.Locale;
import static java.util.Calendar.LONG;
import static java.util.Calendar.SHORT; 
The full code with outputs are here.
package my_proj;
import java.util.Calendar;
import java.util.Locale;
import static java.util.Calendar.LONG;
import static java.util.Calendar.SHORT; 
public class my_first {
public static void main(String[] args) {
Calendar my_cal_d1 = Calendar.getInstance();// created calendar
String str;

str=my_cal_d1.getDisplayName(Calendar.DAY_OF_WEEK, LONG, Locale.US);
System.out.println( str);//Sunday

str=my_cal_d1.getDisplayName(Calendar.DAY_OF_WEEK, SHORT, Locale.UK);
System.out.println( str);//Sun

str= my_cal_d1.getDisplayName(Calendar.MONTH, SHORT, Locale.UK);
System.out.println( str);//Mar

str= my_cal_d1.getDisplayName(Calendar.YEAR, LONG, Locale.UK); 
System.out.println( str);//null

str= my_cal_d1.getDisplayName(Calendar.HOUR, LONG, Locale.UK); 
System.out.println( str);//null

str=my_cal_d1.getDisplayName(Calendar.AM, LONG, Locale.UK);
System.out.println( str);//AD

str= my_cal_d1.getDisplayName(Calendar.AM_PM, LONG, Locale.UK);
System.out.println( str);//am

str= my_cal_d1.getDisplayName(Calendar.ERA, LONG, Locale.UK);
System.out.println( str);//AD
Date & time tutorials


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here

    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2023 All rights reserved worldwide Privacy Policy Disclaimer