Package Com.day10.Calendar;
Import Java.util.Calendar;
public class Demo1calendar {
/**
* @param args
* Common objects (add () and set () methods of the Calendar Class) (Master)
* A: Member method
* public void Add (int field,int amount)
* Public final void set (int year,int month,int date)
* B: Case Demo
* Member methods of the Calendar class are used
*/
public static void Main (string[] args) {
Calendar c=calendar.getinstance ();//parent Class reference to child class object
C.add (Calendar.month, 1);//forward minus or backward for the specified field
C.set (calendar.year,2000);//Modify the specified field
C.set (2000, 7,8);//Modified Date
System.out.println (C.get (calendar.year) + "year" + (C.get (calendar.month) +1) + "month" +
C.get (Calendar.day_of_month) + "Day" +getweek (C.get (Calendar.day_of_week)));
}
public static String Getweek (int week)
{
String[] arr={"", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
return Arr[week];
}
}
Java-calendar class +