可能的原因是 1 方法是自定义的 你当前数据库中没有写入这个方法
2 这个方法是官方的但是 版本号不同 这个方法被取消了
解决的方法 1 写入这个方法调用 2 更换 对应版本的 mysql
public static void main(String[] args) throws Exception {String birthday ="2000-02-29"
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd")
Calendar cal = Calendar.getInstance()
int yearNow = cal.get(Calendar.YEAR)// 年
cal.setTime(formatter.parse(birthday))
int birthyear=cal.get(Calendar.YEAR)
while(birthyear<yearNow){
cal.set(Calendar.YEAR,cal.get(Calendar.YEAR)+1)
birthyear=cal.get(Calendar.YEAR)
}
Date ed=new Date()
Date sd=cal.getTime()
long days=0
if((ed.getTime() - sd.getTime()) / (3600 * 24 * 1000)>0 ){
days=(ed.getTime() - sd.getTime()) / (3600 * 24 * 1000)
System.out.println("距离你生日还有" + days + "天")
}else{
cal.set(Calendar.YEAR,cal.get(Calendar.YEAR)+1)
sd=cal.getTime()
days=(ed.getTime() - sd.getTime()) / (3600 * 24 * 1000)
System.out.println("距离你生日还有" + days + "天")
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)