code: public static Date getLastNDay(Date d, int n, int unitType) {
      	Calendar cal = Calendar.getInstance();
          cal.setTime(d); 
          cal.add(unitType, -n);
          cal.set(Calendar.HOUR_OF_DAY, 0);
          cal.set(Calendar.MINUTE, 0);
          cal.set(Calendar.SECOND, 0);
          cal.set(Calendar.MILLISECOND, 0);
          return cal.getTime();
      }
docs: Get date with n unitType before
  @param d date
  @param n number of units
  @param unitType unit type : one of  Calendar.DAY_OF_YEAR, Calendar.WEEK_OF_YEAR, Calendar.MONTH, Calendar.YEAR;
  @return