Calendar class roll(int field, boolean up)method example
Adds or subtracts (up/down) a single unit of time on the given time field without changing larger fields.
Calendar class roll(int field, boolean up)method example. This example shows you how to use roll(int field, boolean up)method.This method Adds or subtracts (up/down) a single unit of time on the given time field without changing larger fields.
Here is the code:-
/*
* @Program that Adds or subtracts (up/down) a single unit of time on the given
time field without changing larger fields
* Roll1.java
* Author:-RoseIndia Team
* Date:-23-May-2008
*/
import java.util.*;
public class Roll1 {
public static void main(String[] args) {
Calendar c= Calendar.getInstance();
//Displays the current calendar
System.out.println("Year before rolling is "+c.get(Calendar.YEAR));
//Adds or subtracts (up/down) a single unit of time on the given time field
//without changing larger fields.
c.roll(1,true);
//
System.out.println("Year after rolling is "+c.get(Calendar.YEAR));
}
} |
Output of the program:-
Year before rolling is 2008
Year after rolling is 2009 |
|