code: private static int getMonthOfYear(int dayOfYear, int year) {
  
          Integer[] newMonths = getAdjustedMonthDays(year);
  
          if (dayOfYear >= 0) {
              for (int i = 0; i < newMonths.length; i++) {
                  if (dayOfYear < newMonths[i].intValue()) {
                      return i - 1;
                  }
              }
              return 11;
          } else {
              dayOfYear = (isLeapYear(year) ? (dayOfYear + 355)
                      : (dayOfYear + 354));
              for (int i = 0; i < newMonths.length; i++) {
                  if (dayOfYear < newMonths[i].intValue()) {
                      return i - 1;
                  }
              }
              return 11;
          }
      }
docs: Returns month-of-year. 0-based.
  
  @param dayOfYear  day-of-year
  @param year  a year
  @return month-of-year