总是不知道自己现在几岁了,这个程序帮你解决
package com.kuang.demo07;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;public class demo {public static void main(String[] args) throws ParseException {// TODO Auto-generated method stubScanner scanner = new Scanner(System.in);System.out.println("请输入出生年份:");int year = scanner.nextInt();System.out.println("请输入出生月份:");int month = scanner.nextInt();System.out.println("请输入出生日期:");int day = scanner.nextInt();String s = year+"年"+month+"月"+day+"日";//出生日期//获取日期格式化对象SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");//将指定文本解析为日期对象Date d = sdf.parse(s);long chusheng = d.getTime();long dangqian = new Date().getTime();long haomiao = dangqian-chusheng;long tian = haomiao/1000/3600/24;System.out.println("您已经虚度了"+tian+"天");System.out.println("您已经虚度了"+tian/365+"年");}
}