Java 12th job

I, entitled

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, the code

package Birthday;
import java.util.Calendar;
import java.util.Date;
import java.text.SimpleDateFormat;

public class Birthday {
    public static void main(String[] args) {
        Calendar b1 = Calendar.getInstance();
        Calendar b2 = Calendar.getInstance();
        int year = 1996,month = 9,day = 19;          //输入生日
        b1.set(year, month-1, day);
        b2.setTime(new Date());
        long b = b2.getTimeInMillis() - b1.getTimeInMillis();
        int d = (int) (b / 86400000);
        SimpleDateFormat bir = new SimpleDateFormat("出生日期为:yyyy年MM月dd日");
        System.out.println(bir.format(b1.getTime()) + "\n"+"距离今天共" + d + "天");
     }

}

Third, the operating results

 

Guess you like

Origin www.cnblogs.com/anemone0919/p/11924978.html