Java Calendar roll() Method3 Nov 2024 | 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 roll(int field, int amount) in which, the amount of time is passed to roll the specified field by that amount of time. SyntaxParameterfield - the calendar field. up - indicates if the value of the specified time field is to be rolled up or rolled down. Use true if rolling up, false otherwise. ReturnsNA ThrowsNA Example 1Output: Date : Tue Aug 14 17:38:23 PDT 2018 Date after rolling : Sun Sep 08 17:38:23 PDT 2019 Example 2Output: Date : Tue Aug 14 17:42:25 PDT 2018 Date after rolling : Sun Oct 10 19:51:28 PDT 2027 Next TopicJava-calendar-setfirstdayofweek-method |
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 getWeekYear() method of java.util.Calendar class is a public method. This method gets the week year of calendar object and returns in integer the week year of calendar. Syntax public int getWeekYear() Parameter No parameter is passed. Returns Returns in integer week year of current calendar object . Throws UnsupportedOperationException Example 1 import java.util.Calendar; public class JavaCalendargetWeekYearExample1...
1 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 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. Syntax public int get(int field) Parameter Any field of calendar is passed as parameter. Returns Return value of passed field...
3 min read
The getFirstDayOfWeek() method of java.util.Calendar.getFirstDayOfWeek() class. It returns first day of week in integer form. i.e. corresponding integer value of DAY Field. No parameter is passed to getFirstDayOfWeek() method. Syntax public int getFirstDayOfWeek() Parameter No parameter is passed. Returns Returns the first day of the week in integer form. Throws Does not throw...
3 min read
The set() method of Calendar class is used to set the specified calendar field by the specified value. Syntax This method is overloaded in the following ways. public void set(int field, int value) public final void set(int year, int month, int date) public final void set(int year,int month, int date, int...
2 min read
The getActualMaximum() method of java.util.Calendar class returns an integer value which is the Maximum possible value of the calendar field passed as parameter to getActualMaximum() method. For example Maximum value for DATE field is 31, and similarly Maximum value for MONTH field is 11 . Syntax public int...
2 min read
The equals() method compares two objects for equality and returns true if they are equal. The equals() method is provided in the Object class. As object class is the super class of all other classes in java. Calendar class inherits the equals() method. It compares this...
3 min read
The setMinimalDaysInFirstWeek() method of Calendar class is used to set the minimal days required in first week. The value which is to be set as minimal days in first week is passed as parameter. Syntax public void setMinimalDaysInFirstWeek(int value) Parameter Value - this value is set as the minimal days...
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
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