假如我不知道今年是闰年还是平年计算明年的当前年月日(java)

来源:百度知道 编辑:UC知道 时间:2024/06/17 20:12:37
不知道今天号数。、、考虑的时候要把闰年考虑进去。怎么做?
麻烦各位吧代码写完。要能运行的。。我加100分

不知道今年是闰年还是平年计算明年的当前年月日(java):
先判断当年,定义:年数=n,判断是否是闰年: = ((n/4==0 && n/100!=0) || n/400 == 0)下面是详细代码:
public static void main(String[] args) {
Date now = new Date();
int nowYear = now.getYear();
int month = now.getMonth();
long addMillis = 0;
boolean isLeap = false;
if(month <= 2){
isLeap = ((nowYear%4==0 && nowYear%100!=0) || nowYear%400 == 0);
}else{
nowYear += 1;
isLeap = ((nowYear%4==0 && nowYear%100!=0) || nowYear%400 == 0);
}
if(isLeap){
addMillis = ((long)366)*24*3600*1000;
}else{
addMillis = ((long)365)*24*3600*1000;
}
Date nextYear = new Date(System.curr