import java.time.DayOfWeek;
import java.util.Calendar;
import java.util.Date;
public class CalendarTest {
public static void main(String[] args) {
Calendar calendar = Calendar.getInstance();//通过单例创建出对象
calendar.setTime(new Date());
int year = calendar.get(Calendar.YEAR);
//月份加1
int month = calendar.get(Calendar.MONTH)+1;
int day = calendar.get(Calendar.DAY_OF_MONTH);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
System.out.println("现在的时间是:");
System.out.println(year+"年"+month+"月"+day+"日");
System.out.println(hour+"时"+minute+"分"+second+"秒");
int y = 2017,mon = 1,d = 2;//
calendar.set(y, mon, d); // 2017年2月2日
long time1 = calendar.getTimeInMillis();
y = 2017;
mon = 3;
d = 22;
calendar.set(y, mon, d);//2017年4月22日
long time2 = calendar.getTimeInMillis();
long subDay= (time2 - time1)/(1000*60*60*24);
System.out.println(""+new Date(time2));
System.out.println(""+new Date(time1));
System.out.println("相差"+subDay +"天");
}
}