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 source code
/ ** enter the date of birth, a Date object defines the string into a date type, and finally converted milliseconds, output.
* /
Package com1121;
Import java.text.ParseException;
Import the java.text.SimpleDateFormat;
Import java.util.Date;
Import java.util.Scanner;
public class the Test {
public static void main (String [] args) {
// Auto-Generated Stub Method, TODO
Scanner sc = new new Scanner (System.in);
System.out.println ( "Please enter your birth date: If the format MM-dd-yyyy" );
String str = sc.nextLine ();
try{
// Converts a string to a date type
the SimpleDateFormat SimpleDateFormat = new new the SimpleDateFormat ( "the MM-dd-YYYY" );
a Date birthdayDate = (a Date) simpleDateFormat.parse (STR);
a Date nowDate = new new a Date ();
// milliseconds Conversions
Long nowSecond nowDate.getTime = (); // current value ms
Long birthdaySecond birthdayDate.getTime = (); // birthday milliseconds
Long SECOND = (nowSecond-birthdaySecond) / 1000/60/60/24 ;
IF (SECOND < 0 ) {
System.out.println ("Mistyped" );
} the else {
System.out.println ( "You were born altogether so far spent" + second + "My god!" );
}
} The catch (ParseException E) {
// TODO Auto-Generated the catch Block
e.printStackTrace ();
}
}
}