我使用下面的代码来检查的人的生日:日期跳过一年计算下一个生日日期
public class Test_Year {
static int yearsInterval =1;
static int yearsSpecial =0;
static Date dateYearsReg;
public static void main(String[] args){
yearsToNotify(2013, "0001-10-02");
}
public static void yearsToNotify(int yearsElapsedSinceBirth, String dateOfBirth){
Date dt = Convert(d);
Calendar cal = Calendar.getInstance();
cal.setTime(dt);
System.out.println();
yearsSpecial = yearsInterval*(1+(years/yearsInterval));
System.out.println(yearsSpecial);
cal.add(Calendar.YEAR, yearsSpecial);
dateYearsReg = cal.getTime();
System.out.println(dateYearsReg);
}
public static Date Convert(String S){
String dateStr = S;
Date d1 = null ;
try {
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
d1 = f.parse(dateStr);
} catch (ParseException e) {
e.printStackTrace();
}
return d1;
}
}
理想情况下,上述应该给我的下一个生日和今年应该是2014年,但是我得到2015年的一年。系统日期是2014年10月1日的第一天。任何提示?
在这个保护区里,如果我给这样的电话:yearsToNotify(41,“1972-10-17”);我得到正确的值。看来这是与结果的问题时,我用一年0001
你能明确什么是年,d的'yearsToNotify(int years,String d)'函数? – deKajoo 2014-10-01 10:09:44
年份是自出生以来经过的年数,d是出生日期。对不起,我习惯于不使用标准变量名称。 – Skynet 2014-10-01 10:10:36