Java Calendar get() Method3 Nov 2024 | 2 min read The get() method of Calender class returns the value of the parameter fields passed into it. Fields like DAY_OF_MONTH, MONTH, YEAR, WEEK, WEEK_OF_YEAR etc are passed as parameter to this method. SyntaxParameterAny field of calendar is passed as parameter. ReturnsReturn value of passed field as parameter in integer form. ThrowsArrayIndexOutOfBoundsException Example 1Output: Day of month is: 2 Month of year is: 7 and year is : 2018 Today is 2 Day of 7 Month of the year 2018 Example 2Output: Hour is : 8 Minute is: 1 Second is1 Time : 8:1:1 Example 3Output: Date when objectt is created : Thu Aug 02 08:07:16 PDT 2018 date after using add method : Wed Jun 25 08:07:16 PDT 4036 HOUR : 8 MINUTE : 7 SECOND : 16 |
The setWeekDate() method of java.util.Calendar class sets the current date with specified integer value as the parameter. These values are the weekYear, weekOfYear, and dayOfWeek. Syntax public void setWeekDate(int weekYear, int weekOfYear, int dayOfWeek) Parameter weekYear - the week year weekOfYear - the week number based on weekYear dayOfWeek - the day...
2 min read
The getAvailableLocals() method of java.util.Calendar class returns an array of all locales available in java runtime environment. The array of locales contains locales for which localized Calendar instances are available. getAvailableLocals() method is a static method. Syntax public static Locale[] getAvailableLocales() Parameter This method doesn't accept any parameter. Returns This method...
2 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 internalGet() method of java.util.Calendar class is a final, and protected method. This method returns the value of the calendar field passed as a parameter. Syntax protected final int internalGet(int field) Parameter field - the given calendar field. Returns the value for the given calendar field. Throws Does not throw Exception. Example 1 import java.util.GregorianCalendar; public class...
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 setTime () method of java.util.Calendar class is used to set the Time of current calendar object. A Date object id is passed as the parameter into this method. Syntax public final void setTime(Date date) Parameter date - a date object. Returns Does not return value. Throws Does not throw Exception. Example 1 import java.util.*; public class...
2 min read
//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...
5 min read
The setTimeInMillis () method of java.util.Calendar class is used to set the current time in millisecond. The date value to be set is passed as long into this method. Syntax public void setTimeInMillis(long millis) Parameter millis - the new time in UTC milliseconds. Returns Does not return value. Throws Does not throw Exception. Example 1 import...
2 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