第12次作业--你的生日
题目:利用Calendar类计算自己的出生日期距今天多少天,再将自己的出生日期利用SimpleDateFormat类设定的格式输出显示。
public class timuyi { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sca = new Scanner(System.in); int year = sca.nextInt(); int month = sca.nextInt(); int day = sca.nextInt(); //出生日期 Calendar calendar = Calendar.getInstance(); calendar.set(year,month-1,day); System.out.println(year+"年"+month+"月"+day+"日"+"出生日期"); //现在时间 Date nowTime = new Date(); SimpleDateFormat matter = new SimpleDateFormat("yyyy年MM月dd日现在时间"); Calendar calendar1 = Calendar.getInstance(); calendar1.setTime(nowTime); System.out.println(matter.format(nowTime)); long birday = calendar.getTimeInMillis(); long nowday = calendar1.getTimeInMillis(); long time = nowday-birday; long day1 = time/1000/60/60/24; System.out.println("出生日期距离今天"+day1+"天"); } }