code: static public long msDiffJulianToGregorian(java.util.Date date)
    {
      // get the year of the date
      Calendar cal = Calendar.getInstance();
      cal.setTime(date);
      int year = cal.get(Calendar.YEAR);
      int month = cal.get(Calendar.MONTH);
      int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
  
      // if date is before 1582-10-05, apply the difference
      // by (H-(H/4)-2) where H is the hundreds digit of the year according to:
      // http://en.wikipedia.org/wiki/Gregorian_calendar
      if (date.getTime() < -12220156800000L)
      {
        // for dates on or before 02/28, use the previous year otherwise use
        // current year.
        // TODO: we need to revisit this since there is a potential issue using
        // the year/month/day from the calendar since that may not be the same
        // year/month/day as the original date (which is the problem we are
        // trying to solve here).
  
        if (month == 0 || (month == 1 && dayOfMonth <= 28))
        {
          year = year - 1;
        }
  
        int hundreds = year / 100;
        int differenceInDays = hundreds - (hundreds / 4) - 2;
  
        return differenceInDays * 86400000;
      }
      else
      {
        return 0;
      }
    }
docs: For dates before 1582-10-05, calculate the number of millis to adjust.
  
  @param date date before 1582-10-05
  @return millis needs to be adjusted