import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class CalendarTest {
public static void main(String[] args) {
Calendar cal1=new GregorianCalendar(2019, 7, 23, 22, 11, 45);
//System.out.println(cal1.get(Calendar.YEAR));
//System.out.println(cal1.get(Calendar.DATE));
//cal.set(Calendar.YEAR, 2020);
//cal.set(2020, 5, 3, 12, 34, 89);
//cal.add(Calendar.MONTH, -8);
Date dd=cal1.getTime();//把日期转化成时间
System.out.println(dd);
Calendar cal2=new GregorianCalendar(); //把时间转化成日期
cal2.setTime(dd); //Calendar没有构造函数可以接收Date对象,必须先创建Calendar对象,然后调用setTime()方法
System.out.println(cal2);
}
}
转载于:https://www.cnblogs.com/ccbTony/p/11380257.html