Javatpoint Logo
Javatpoint Logo

Java Calendar roll() Method

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.

Syntax

Parameter

field - 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.

Returns

NA

Throws

NA

Example 1

Test it Now

Output:

Date : Tue Aug 14 17:38:23 PDT 2018
Date after rolling : Sun Sep 08 17:38:23 PDT 2019

Example 2

Test it Now

Output:

Date : Tue Aug 14 17:42:25 PDT 2018
Date after rolling : Sun Oct 10 19:51:28 PDT 2027




Please Share

facebook twitter google plus pinterest