tags:

views:

118

answers:

1

hello

what is the diference between roll() and add() in java ?

/*this the class that i wanted to see if i can use add in place of roll . and thank you */

    mydate.roll(Calendar.MINUTE, true);
    int nextminutes = mydate.get(Calendar.MINUTE);
    int nexttseconds = mydate.get(Calendar.SECOND);
    while(count<1000000){
        System.out.println(sentence);
        GregorianCalendar now = new GregorianCalendar();

    if(mydate.get(Calendar.MINUTE)>= nextminutes){
        break;
    }   
    }
    count++;
    System.out.println("i wrote the sentence"+count+"time.");


}

}

+4  A: 

If you're working on a calendar:

"Calendar.roll changes a specific unit and leaves 'larger' ( in terms of time - month is 'larger' than day) units unchanged. The API example is that given a date of August 31, 1999, rolling by (Calendar.MONTH, 8) yields April 30, 1999. That is, the DAY was changed to meet April's maximum, but the 'larger' unit, YEAR, was unchanged.

Calendar.add will cause the next 'larger' unit to change, if necessary. That is, given a date of August 31, 1999, add(Calendar.MONTH, 8) yields April 30, 2000. add() also forces a recalculation of milliseconds and all fields. "

DOK