输入两个日期,使用Calendar来表示时间,并计算两个日期之间相隔的天数。

import java.util.Calendar;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Calendar c=Calendar.getInstance();
        Scanner read=new Scanner(System.in);
        c.set(read.nextInt(),read.nextInt(),read.nextInt());
        long time1=c.getTimeInMillis();
        c.set(read.nextInt(),read.nextInt(),read.nextInt());
        long time2=c.getTimeInMillis();
        long time=(time2-time1)/(1000*60*60*24);
        System.out.println(time);
    }
}

0

Leave a Reply

Your email address will not be published.