set(int, int, int): This method is available in java.util.GregorianCalendar class of Java.
Syntax:
void java.util.Calendar.set(int year, int month, int date)
This method takes three arguments of type int as its parameters. This method sets the values for the calendar fields YEAR, MONTH, and DAY_OF_MONTH.
Note: Previous values of other calendar fields are retained.
Parameters: Three parameters are required for this method.
year: the value used to set the YEAR calendar field.
month: the value used to set the MONTH calendar field.
date: the value used to set the DAY_OF_MONTH calendar field.
Returns: NA
Exceptions: NA
Approach
Java
import java.util.GregorianCalendar;public class GregorianCalendarset2 {public static void main(String[] args) {GregorianCalendar cal = new GregorianCalendar();int year = 2022, month = 1, date = 12;cal.set(year, month, date);System.out.println(cal);}}
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=2022,MONTH=1,WEEK_OF_YEAR=8,WEEK_OF_MONTH=3,DAY_OF_MONTH=12,DAY_OF_YEAR=49,DAY_OF_WEEK=6,DAY_OF_WEEK_IN_MONTH=3,AM_PM=0,HOUR=8,HOUR_OF_DAY=8,MINUTE=58,SECOND=7,MILLISECOND=941,ZONE_OFFSET=19800000,DST_OFFSET=0]
No comments:
Post a Comment