Getting the number of days between two Dates

You can create two date objects, get the number of milliseconds that have passed since Jan 1, 1970 for each of them, make the difference and divide that back by the number of milliseconds per day (= 3600sec/hr * 24hrs * 1000ms)

Main.java:

import java.util.*;
 
public class Main {
   public static void main(String []args) {
      Calendar date1 = Calendar.getInstance();
      date1.set(2001, 6, 4);
 
      Calendar date2 = Calendar.getInstance();
      date2.set(1972, 12, 20);
 
      long diff = (date1.getTime().getTime() - date2.getTime().getTime()) / (3600*24*1000);
      System.out.println("Difference in time: " + diff);
   }
}