Calendar类的add()和set()方法)
* A:成员方法
* public void add(int field,int amount)
* public final void set(int year,int month,int date)
* B:案例演示
* Calendar类的成员方法使用
案例:
package com.heima.otherclass;
import java.util.Calendar;
public class Demo9_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) + "年" + getNum((c.get(Calendar.MONTH)+1))
+ "月" + getNum(c.get(Calendar.DAY_OF_MONTH)) + "日" + getWeek(c.get(Calendar.DAY_OF_WEEK)));
}
}
|
|