Calendar class roll(int field, int amount)method example
Adds the specified (signed) amount to the specified calendar field without changing larger fields.
Calendar class roll(int field, int amount)method example. This example shows you how to use roll(int field, int amount)method.This method Adds the specified (signed) amount to the specified calendar field without changing larger fields.
Here is the code:-
/*
* @Program that Adds the specified (signed) amount to the specified calendar
field without changing larger fields.
* Roll2.java
* Author:-RoseIndia Team
* Date:-23-May-2008
*/
import java.util.*;
public class Roll2 {
public static void main(String[] args) {
Calendar c= Calendar.getInstance();
//Displays the current calendar
System.out.println("Day before rolling is "+c.get(Calendar.DAY_OF_MONTH));
//Adds the specified (signed) amount to the specified calendar
//field without changing larger fields.
c.roll(Calendar.DAY_OF_MONTH, -5);
System.out.println("Day after rolling is "+c.get(Calendar.DAY_OF_MONTH));
}
} |
Output of the program:-
Day before rolling is 24
Day after rolling is 19 |
|