Java - Write code to compare Day

Requirements

Write code to compare Day

Demo

import java.util.Calendar;
import java.util.Date;

public class Main {
  public static void main(String[] argv) {
    Date start = new Date();
    Date end = new Date();
    System.out.println(compareDay(start, end));
  }//from  www.j  a  v a2  s .c o m

  public static long compareDay(Date start, Date end) {
    long day = compareDate(start, end);
    return day / 1000 / 60 / 60 / 24;
  }

  public static long compareDate(Date start, Date end) {
    long temp = 0;
    Calendar starts = Calendar.getInstance();
    Calendar ends = Calendar.getInstance();
    starts.setTime(start);
    ends.setTime(end);
    temp = ends.getTime().getTime() - starts.getTime().getTime();
    return temp;
  }
}

Related Exercise