计算出生到现在多少天
//计算出生到现在多少天
public class Test08 {
// 1 天 = 24 × 60 × 60 = 86400 秒。= 86400 秒 * 1000 = 86400000毫秒
public static void main(String[] args) throws ParseException {
//输入出生日期 格式为yyyy-MM-dd
Scanner sc = new Scanner(System.in);
System.out.println(“输入出生日期 格式为yyyy-MM-dd”);
String birthday = sc.nextLine();
//解析出生日期
SimpleDateFormat s = new SimpleDateFormat(“yyyy-MM-dd”);
Date birthdayDate = s.parse(birthday);
//获取出生日期的毫秒值
long birthdayTime = birthdayDate.getTime();
//获取当前日期的毫秒值
Date nowDate = new Date();
long nowDateTime = nowDate.getTime();
//当前日期的毫秒值-出生日期的毫秒值
long time=nowDateTime-birthdayTime;
//毫秒转换为天数
System.out.println(“出生了”+time/24/60/60/1000+“天”);
}
}
更多推荐
计算出生到现在多少天
发布评论