java 12th job - your birthday

Topic: Using the 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.

 Code:

import java.util.*;
import java.text.*;
public class Test3 {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println("请输入出生年,月,日:");
        Scanner reader = new Scanner(System.in);
        int year = reader.nextInt();
        int month = reader.nextInt();
        int day = reader.nextInt();
        
        NowDate Calendar = Calendar.getInstance (); // get today's date 
        
        Calendar Calendar = Calendar.getInstance (); // get the birthday date 
        calendar.set (year, month The-1, Day);           // get the birthday date 
        Long TIME1 = Calendar .getTimeInMillis ();    // time of birth value (in milliseconds) 
        Long TIME2 = NowDate.getTimeInMillis ();     // time of day value 
        Long days_Mill = (TIME2-TIME1) / (1000 * 3600 * 24); // two date of milliseconds apart 
        Long days = Long.valueOf (String.valueOf (days_Mill)); // two dates in number of days apart 
        
        System.out.println ( "You go through from birth to now a total of:" + days + "days "); 
        SimpleDateFormat the Simple = new new SimpleDateFormat ( "your date of birth is: yyyy Year MM Month dd Day" ); 
        System.out.println (simple.format (calendar.getTime ())); 
    

    } 

}

 

Screenshot:

 

Guess you like

Origin www.cnblogs.com/19980712mj/p/11921374.html