推遲一周示例:
Calendar curr = Calendar.getInstance(); //獲取當前時間
curr.set(Calendar.DAY_OF_MONTH,curr.get(Calendar.DAY_OF_MONTH)+7); //給當前時間增加一周
Date date=curr.getTime();//獲取新的時間
推遲一個月示例:
Calendar curr = Calendar.getInstance();
curr.set(Calendar.MONTH,curr.get(Calendar.MONTH)+1); //增加一月
Date date=curr.getTime();
推遲一年示例:
Calendar curr = Calendar.getInstance();
curr.set(Calendar.YEAR,curr.get(Calendar.YEAR)+1); //增加一年
Date date=curr.getTime();
//判斷是否是閏年
int years=curr.get(Calendar.YEAR);
if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
//判斷是否閏年,閏年366天
days = 366;
}else{
days=365;
}
