import java.util.*;
class DateExample
{
public static void main(String args[])
{
Scanner read=new Scanner(System.in);
System.out.println("输入第一个日期的年份:");
int yearOne=read.nextInt();
System.out.println("输入该年的月份:");
int monthOne=read.nextInt();
System.out.println("输入该月的日期:");
int dateOne=read.nextInt();
System.out.println("输入第二个日期的年份:");
int yearTwo=read.nextInt();
System.out.println("输入该年的月份:");
int monthTwo=read.nextInt();
System.out.println("输入该月的日期:");
int dateTwo=read.nextInt();
Calendar calendar=Calendar.getInstance();
calendar.set(yearOne,monthOne,dateOne);
long time1=calendar.getTimeInMillis();
calendar.set(yearTwo,monthTwo,dateTwo);
long time2=calendar.getTimeInMillis();
Date date1=new Date(time1);
Date date2=new Date(time2);
if(date2.equals(date1))
{
System.out.println("两个日期的年,月,日相同") ;
}
else if(date2.after(date1))
{
System.out.println(" 第二个日期大于第一");
}
else if(date2.before(date1))
{
System.out.println("第二个日期小于第一 ");
}
long 相隔天数=(time2-time1)/(1000*60*60*24);
System.out.printf("%d年%d月%d日%d年%d月%d日相隔%d天数",yearOne,monthOne,dateOne,yearTwo,monthTwo,dateT
编译成功但不能运行的问题大家来看看把