CalendarUtils { public static int dayOfYear(final Date date) { return fromDateToCalendar(date).get(Calendar.DAY_OF_YEAR); } private  CalendarUtils(); static Calendar fromDateToCalendar(final Date date); static int weekDay(final Date date); static int month(final Date date); static int weekOfYear(final Date date); static int day(final Date date); static int dayOfYear(final Date date); static int year(final Date date); static boolean isLeapYear(final Date date); static boolean isAM(final Date date); static boolean isPM(final Date date); static int hour12(final Date date); static int hour24(final Date date); static int minute(final Date date); static int second(final Date date); static int millisecond(final Date date);  }
@Test public void testDayOfYear() throws Exception { final Date day1Date = date(2015, 1, 31); final Date day2Date = date(2000, 2, 29); final Date day3Date = date(2000, 3, 1); final int day1 = CalendarUtils.dayOfYear(day1Date); final int day2 = CalendarUtils.dayOfYear(day2Date); final int day3 = CalendarUtils.dayOfYear(day3Date); assertThat(day1, is(31)); assertThat(day2, is(60)); assertThat(day3, is(61)); }