12th job - your birthday

I, entitled

With a Calendar class is calculated from the date of his birth today, how many days, then your date of birth using the format of the output SimpleDateFormat class setting display.

Second, the code

import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

public class shijian {

    public static void main(String[] args) {
    Date now =new Date();

    Scanner reader = new Scanner(System.in);
    System.out.println("请输入出生年月日:");    
    int year =reader.nextInt();
    int month =reader.nextInt();
    int day =reader.nextInt();
    Calendar calendar=Calendar.getInstance();
    Calendar calendar1=Calendar.getInstance();
    calendar.set(year, month-1, day);
    calendar1.setTime(now);
    System.out.println(year+"年"+month+"月"+day+"日"+"出生日期");
    System.out.print ( "from today" + ((calendar1.getTimeInMillis () - calendar.getTimeInMillis ()) / (1000 * 60 * 60 * 24)) + " days");     
 
    }

}

 

Third, the operating results

Guess you like

Origin www.cnblogs.com/lyqqqq/p/11918346.html