思路:用当前日期的毫秒值减去你的出生日期的毫秒值,然后取得的差值转化为天数
package Test02;//包名
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Scanner;
import java.util.Date;
public class DateTest {
public static void main(String[] args) throws ParseException {
Scanner input=new Scanner(System.in);
System.out.println("请输入你的出生日期,格式为yyyy-MM-dd:");
String birthdayDateString = input.next();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
Date birthday = sdf.parse(birthdayDateString);
long birthdayDateTime = birthday.getTime();
long todayTime = new Date().getTime();
long time=todayTime-birthdayDateTime;
long day=time/(1000*60*60*24);//转化为天数
System.out.println("你生活了"+day+"天");
}
}