Twelfth job - Birthday

A 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.

Second Source:

 1 package String;
 2 import java.text.SimpleDateFormat;
 3 import java.util.Date;
 4 import java.util.Scanner;
 5 public class Birth {
 6     public static void main(String[] args) throws Exception {
 7         System.out.println("请输入出生日期,格式为yyyy-MM-dd:");
 8         Scanner reader=new Scanner(System.in);
 9         String date=reader.next();
10         SimpleDateFormat format = newThe SimpleDateFormat ( "the MM-dd-YYYY" );
 . 11          a Date Birthday = format.parse (DATE);    
 12 is          a Date nowDate = new new a Date ();      // get the current date 
13 is          Long nowSecond nowDate.getTime = (); // Switch ms value is scaled 
14          Long birthdaySecond = birthday.getTime ();
 15          Long SECOND = nowSecond- birthdaySecond;
 16          IF (SECOND <0 ) {
 . 17              System.out.println ( "can not be calculated" );
 18 is          } the else {
 . 19             System.out.println ( "date of birth from now" + second / 1000/60/ 60/24 + " days" );
 20 is              
21 is          }
 22 is          System.out.println ( "Output:" DATE +);   // the format output 
23      }
 24 }

III. Run shot

Guess you like

Origin www.cnblogs.com/gywx/p/11917932.html