package com.day10.Calendar;
import java.util.Calendar;
public class Demo1Calendar {
/**
* @param args
* 常见对象(Calendar类的add()和set()方法)(掌握)
* A:成员方法
* public void add(int field,int amount)
* public final void set(int year,int month,int date)
* B:案例演示
* Calendar类的成员方法使用
*/
public static void main(String[] args) {
Calendar c=Calendar.getInstance();//父类引用指向子类对象
c.add(Calendar.MONTH, 1);//对指定的字段进行向前减或者向后加
c.set(Calendar.YEAR,2000);//修改指定字段
c.set(2000, 7,8);//修改了年月日
System.out.println(c.get(Calendar.YEAR)+"年"+(c.get(Calendar.MONTH)+1)+"月"+
c.get(Calendar.DAY_OF_MONTH)+"日"+getWeek(c.get(Calendar.DAY_OF_WEEK)));
}
public static String getWeek(int week)
{
String[] arr={"","星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
return arr[week];
}
}