Calendar calendar = Calendar.getInstance();
demo04(calendar);
}
public static void demo02(Calendar calendar){
calendar.set(Calendar.YEAR, 2050);
int year = calendar.get(Calendar.YEAR);
System.out.println(year);
calendar.set(Calendar.MONTH,12);
System.out.println(calendar.get(Calendar.MONTH));
calendar.set(Calendar.DATE,5);
System.out.println(calendar.get(Calendar.DATE));
}
// 根据日历的规则为给定的日历字段添加或者减去指定的时间量
public static void demo03(Calendar calendar){
calendar.add(Calendar.YEAR,2);
calendar.add(Calendar.MONTH, -3);
System.out.println(calendar.get(Calendar.YEAR));
System.out.println(calendar.get(Calendar.MONTH));
}
public static void demo04(Calendar calendar){
Date time = calendar.getTime();
System.out.println(time);
}
//获取给定的字段值
public static void demo01(Calendar calendar){
int year = calendar.get(Calendar.YEAR);
System.out.println(year);
int month = calendar.get(Calendar.MONTH);
System.out.println(month + 1);
int date = calendar.get(Calendar.DATE);
System.out.println(date);
}
原文:https://www.cnblogs.com/zlh109/p/14070528.html