public Long inday( Date brithday ){SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");String clidate = "1978-03-30";Calendar cToday = Calendar.getInstance(); // 存今天Calendar cBirth = Calendar.getInstance(); // 存生日cBirth.setTime(brithday); // 设置生日cBirth.set(Calendar.YEAR, cToday.get(Calendar.YEAR)); // 修改为本年Integer days;if (cBirth.get(Calendar.DAY_OF_YEAR) < cToday.get(Calendar.DAY_OF_YEAR)) {// 生日已经过了,要算明年的了days = cToday.getActualMaximum(Calendar.DAY_OF_YEAR) - cToday.get(Calendar.DAY_OF_YEAR);days += cBirth.get(Calendar.DAY_OF_YEAR);} else {// 生日还没过days = cBirth.get(Calendar.DAY_OF_YEAR) - cToday.get(Calendar.DAY_OF_YEAR);}// 输出结果if (days == 0) {System.out.println("今天生日");} else {System.out.println("距离生日还有:" + days + "天");}return days.longValue();}
100字范文,内容丰富有趣,生活中的好帮手!