分析
1.使用Scanner
2.将字符串的时间转换为Date
3.获取生日毫秒值 再获取当前系统的毫秒值
public static void main(String[] args) throws Exception{
Scanner input=new Scanner(System.in);
System.out.println("请输入生日");
String birthday=input.next();
//时间转化为Date
SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd");
Date date=sf.parse(birthday);
//获取毫秒值
long time= date.getTime();
//获取当前系统的时间
long currentTime = System.currentTimeMillis();
System.out.println((currentTime - time) / 1000 / 60 / 60 / 24+"天");
}
运行截图
第二种方式
Calendar
public s