[Java] 纯文本查看 复制代码
public class Test {
public static void main(String[] args) throws ParseException {
Scanner input=new Scanner(System.in);
System.out.println("请输入您的生日,格式:yyyy-MM-dd");
String birthDay=input.next();
//使用Dateformat中的parse方法,把字符串中的出生日期解析为date格式
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
Date birthDate=sdf.parse(birthDay);
//转化为毫秒值
long birthDateTime=birthDate.getTime();
long todayTime=new Date().getTime();
long time=todayTime-birthDateTime;
//转化为天数
System.out.println("您已经出生了"+(time/1000/60/60/24)+"天");
}
}public class Test {
public static void main(String[] args) throws ParseException {
Scanner input=new Scanner(System.in);
System.out.println("请输入您的生日,格式:yyyy-MM-dd");
String birthDay=input.next();
//使用Dateformat中的parse方法,把字符串中的出生日期解析为date格式
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
Date birthDate=sdf.parse(birthDay);
//转化为毫秒值
long birthDateTime=birthDate.getTime();
long todayTime=new Date().getTime();
long time=todayTime-birthDateTime;
//转化为天数
System.out.println("您已经出生了"+(time/1000/60/60/24)+"天");
}
}