- package test;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.Scanner;
- public class Test01 {
- public static void main(String[] args) throws Exception {
- Scanner sc=new Scanner(System.in);
- System.out.println("请输入你的生日:格式为yyyy-yy-yy");
- String line=sc.nextLine();
-
- SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
- Date d=sdf.parse(line);
-
- long time=d.getTime();
-
- long timeNow=System.currentTimeMillis()-time;
-
- long day=timeNow/1000/60/60/24;
-
- System.out.println("你今年:"+(day/365)+"岁");
-
-
- }
- }
复制代码
|
|