roll(int, boolean): This method is available in java.util.Calendar class of Java.
Syntax:
void java.util.Calendar.roll(int field, boolean up)
This method takes two arguments one of type int and the other of type boolean as its parameters. This method adds or subtracts (up/down) a single unit of time on the given time field without changing larger fields.
Parameters: Two parameters are required for this method.
field: the time 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
Exceptions: NA
Approach
Java
import java.util.Calendar;public class Calendarroll {public static void main(String[] args) {// create a calendarCalendar calendar = Calendar.getInstance();int field = 1;boolean up = true;calendar.roll(field, up);System.out.println(calendar.clone());}}
Output:
java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Asia/Calcutta",offset=19800000,dstSavings=0,useDaylight=false,transitions=7,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2023,MONTH=0,WEEK_OF_YEAR=5,WEEK_OF_MONTH=5,DAY_OF_MONTH=23,DAY_OF_YEAR=23,DAY_OF_WEEK=1,DAY_OF_WEEK_IN_MONTH=4,AM_PM=1,HOUR=10,HOUR_OF_DAY=22,MINUTE=11,SECOND=30,MILLISECOND=299,ZONE_OFFSET=19800000,DST_OFFSET=0]
No comments:
Post a Comment