第12次作业--你的生日
题目:利用Calendar类计算自己的出生日期距今天多少天,再将自己的出生日期利用SimpleDateFormat类设定的格式输出显示
package cn.exercise; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Scanner; /** * @author WH * @project Java * @package cn.exercise * @date 2019/11/24 17:38 */ public class WhBirthday { public static void main(String[] args) { System.out.println("input your birthday:"); Date now = new Date(); Scanner scanner=new Scanner(System.in); int year=scanner.nextInt(); int month=scanner.nextInt(); int day=scanner.nextInt(); Calendar calendar=Calendar.getInstance(); calendar.set(1998, Calendar.AUGUST,15); SimpleDateFormat matter=new SimpleDateFormat("yyyy年MM月dd日"); System.out.println(matter.format(calendar.getTime())); int dayday= (int)((now.getTime()-calendar.getTimeInMillis())/(1000*60*60*24)); System.out.println(dayday); } }