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


GregorianCalendarclass 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.
 * Roll.java 
 * Author:-RoseIndia Team
 * Date:-27-May-2008
 */
import java.util.*;

public class Roll {

    public static void main(String[] args) {
        GregorianCalendar g = new GregorianCalendar(2004615);
//Displays the date of the Calendar
        System.out.println("Current Year of the Calendar is: " + g.get(Calendar.YEAR));
//Adds or subtracts (up/down) a single unit of time on the 
        // given time field without changing larger fields.
        g.roll(1true);
        System.out.println("Current Year of the Calendar is: " + g.get(Calendar.YEAR));
    }
}

Output of the program:-
Current Year of the Calendar is: 2004
Current Year of the Calendar is: 2005

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US