package cn.itcast2;
import java.util.Calendar;
/*
* Calendar:日历类
* 构造方法:
* 一般不使用子类构造,而是通过父类返回实例对象的方法创建对象
* Calendar rightNow = Calendar.getInstance();
*
* 普通方法:
* public int get(int field) 获取指定字段的值 字段中的月份是从0-11
* public final void set(int year,int month, int date) 设置年月日
* public abstract void add(int field, int amount) 为某个字段添加某个量
* public final Date getTime() 给我一个日历对象 还你一个日期对象
*/
public class Demo3 {
public static void main(String[] args) {
Calendar rightNow = Calendar.getInstance();
System.out.println(rightNow);
rightNow.set(2015, 5, 22);
rightNow.add(Calendar.YEAR, 1);
int i = rightNow.get(Calendar.YEAR);
int j = rightNow.get(Calendar.MONTH);
int k = rightNow.get(Calendar.DAY_OF_MONTH);
System.out.println(i+"年"+(j+1)+"月"+k+"日");
//找到rightNow变量的毫秒值
long time = rightNow.getTime().getTime();
System.out.println(time);
}
}
|
|