Java Calendar getDisplayName() Method //return String3 Nov 2024 | 4 min read 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. SyntaxParameterfield - 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. ReturnsThe string representation of field passed as parameter in specified format (style) and local is returned. ThrowsIllegalArgumentExeption NullPointerException Example 1Output: Sunday Monday Tuesday Wednesday Thursday Friday Saturday Example 2Output: 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 3Output: Days of year do not have String representation null null null null null null null Java Calendar getDisplayName(int field, int style, Locale locale) MethodThe 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. SyntaxParameterfield - 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. ReturnsThe Map representation of field passed as parameter in specified format (style) and local is returned. Local and style is also passed as parameter. ThrowsIllegalArgumentExeption NullPointerException Example 1Output: List of Days in a week are : {Friday=6, Monday=2, Saturday=7, Sunday=1, Thursday=5, Tuesday=3, Wednesday=4} Example 2Output: 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} Next TopicJava-calendar-getfirstdayofweek-method |
The getTimeInMillis() method of java.util.Calendar class returns the current time in millisecond. This method returns a long value. Syntax public long getTimeInMillis() Parameter No parameter is passed. Returns The current time as UTC milliseconds. Throws Throws InterruptedException Example 1 import java.util.Calendar; public class JavaCalendargetTimeInMillisExample1 { public static void main(String[] args) throws InterruptedException { ...
2 min read
The getTime() method of java.util.Calendar class is a final method. This method gets the time value of calendar object and returns the date. Syntax public final Date getTime() Parameter No parameter is passed. Returns Returns a date which represents time value of calendar object. Throws Does not throw exception. Example 1 import java.util.*; public class JavaCalendargetTimeExample1 extends...
2 min read
The getTimeZone() method of java.util.Calendar class gets the TimeZone of calendar object and returns a TimeZone object. Syntax public TimeZone getTimeZone() Parameter No parameter is passed. Returns Returns the TimeZone object. Throws Does not throw an exception. Example 1 import java.util.Calendar; import java.util.TimeZone; public class JavaCalendargetTimeZoneExample1 { public static void main(String[] args) { Calendar mycal = Calendar.getInstance(); ...
1 min read
The isWeekDateSupported() method of Calendar class returns the Boolean value. It checks if this calendar supports the week date. The default value is false. Syntax public boolean isWeekDateSupported() Parameter No parameter is passed. Returns Returns the Boolean value. Throws Does not throw Exception. Example 1 import java.util.Calendar; public class JavaCalendarisWeekDateSupportedExample1 { public static void...
2 min read
java.util.Calendar.before() is a method in Calendar class of java.util package. The method returns true if the time represented by this Calendar is before the time represented by when Object. If it is not the case, false is returned. Syntax public boolean before(Object when) Parameter When - when is the Object...
4 min read
The getWeeksInWeekYear() method of java.util.Calendar class returns the total number of weeks in a week year in the integer form. Syntax public int getWeeksInWeekYear() Parameter No parameter is passed. Returns Returns the integer number of weeks in week year Throws UnsupportedOperationException: if any week number is not defined in the calendar. Example 1 import java.util.Calendar; public class...
1 min read
The roll () method of Calendar class increases or decreases the specified calendar field by one unit without affecting the other field. For example, if the YEAR field is passed as the parameter. It will roll only the YEAR field. The roll() method is overloaded as...
2 min read
The getMaximum() method of java.util.Calendar class is an abstract method. This method is used with calendar object to get the maximum value of specified calendar field as parameter. Syntax public abstract int getMaximum(int field) Parameter field - the calendar field. Returns The maximum value for the given calendar field. Throws Do not throw any...
3 min read
The getLeastMaximum() method of java.util.Calendar class is an abstract method. This method returns smallest value from all maximum value for field specified as parameter to the method. It takes field in integer form as parameter. And returns an integer. Syntax public abstract int getLeastMaximum(int field) Parameter field - the...
3 min read
The getInstance() method of java.util.Calendar class is a Static method. This method is used with calendar object to get the instance of calendar according to current time zone set by java Runtime environment. Syntax public static Calendar getInstance() public static Calendar getInstance(Locale aLocale) public static Calendar getInstance(TimeZone zone, Locale aLocale) public...
5 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India