A:成员方法
* public void add(int field,int amount)
* public final void set(int year,int month,int date)
import java.util.Calendar;
//* A:成员方法
//* public void add(int field,int amount)
//* public final void set(int year,int month,int date)
public class Demo9_Calendar {
public static void main(String[] args) {
// TODO Auto-generated method stub
Calendar c = Calendar.getInstance();//父类引用指向子类对象
System.out.println(c.get(Calendar.YEAR)+"年"+getNum((c.get(Calendar.MONTH)+1))+"月"+getNum(c.get(Calendar.DAY_OF_MONTH))+"日"
+getWeenk(c.get(Calendar.DAY_OF_WEEK)));//未调用add和set方法前
c.add(Calendar.YEAR, 1);//对指定的字段向前减或者向后加
c.set(2088,11,12);//修改指定字段
System.out.println(c.get(Calendar.YEAR)+"年"+getNum((c.get(Calendar.MONTH)+1))+"月"+getNum(c.get(Calendar.DAY_OF_MONTH))+"日"
+getWeenk(c.get(Calendar.DAY_OF_WEEK)));//添加后
}
public static String getWeenk(int week){
String [] arr = {"","星期日","星期一","星期二","星期三","星期四","星期五","星期六",};//定义一个数组
return arr[week];//返回值
}
/*如果是个数前面补0,
* */
public static String getNum(int num) {
return num>9?""+num:"0"+num;
}
}