java代码计算出生到现在的天数!!

此Java代码是算出生到现在过了多少天

   public static void main(String[] args) throws ParseException {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入出生年份");
        String d1 = scanner.next();
        //获取日期化格式对象
        SimpleDateFormat rq= new SimpleDateFormat("yyyyMMdd");
        Date d = rq.parse(d1);
        System.out.println(d.getTime());
         long chusheng = d.getTime();
        long dangqian = new Date().getTime();
        long haomiao = dangqian-chusheng;
        long tian = haomiao/(1000*60*60*24);
        System.out.println("你已经活了"+tian+"天");
    }


    }

你可能感兴趣的:(java代码计算出生到现在的天数!!)