12th birthday job you ----

topic:

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.

First, the code

Package CN;
 Import the java.text.SimpleDateFormat;
 Import the java.util.Calendar;
 Import java.util.Date;
 Import java.util.Scanner; 

public  class the Test { 

    
    public  static  void main (String [] args) { 
        Scanner Reader = new new Scanner (System.in); 
        System.out.println ( "Please enter a date of birth Please enter a space between (years and months and days yyyy month dd day in mm)" );
         int year = reader.nextInt ();
         int month the = reader.nextInt ();
         int Day = reader.nextInt (); 
        Calendar Calendar =Calendar.getInstance (); 
        calendar.set (year, month The -1 , Day); 
        SimpleDateFormat matter1 = new new SimpleDateFormat ( "Your birthday:" + "yyyy Year MM Month dd Day" ); 
        System.out.println (matter1. format (calendar.getTimeInMillis ())); 
        Calendar nowdate = Calendar.getInstance (); 
        nowdate.setTime ( new new a Date ());        
        
        System.out.println ( "you have been born ago" + (nowdate.getTimeInMillis () - calendar.getTimeInMillis ()) / (1000 * 60 * 60 * 24) + " days" ); 

        
        
        

        

    } 

}

Second, run output

Guess you like

Origin www.cnblogs.com/wjq98/p/11919804.html