根据int类型年份获取一年中所有日期的集合

/**
 * 获取某一年内所有日期集合
 * @param year
 * @return
 */
public static List getAllDatesInYear(int year) {
    List dates = new ArrayList<>();

    LocalDate startDate = LocalDate.of(year, Month.JANUARY, 1);
    LocalDate endDate = LocalDate.of(year, Month.DECEMBER, 31);

    LocalDateTime startDateTime = startDate.atStartOfDay();
    LocalDateTime endDateTime = endDate.atTime(LocalTime.MAX);

    while (!startDateTime.isAfter(endDateTime)) {
        Date date = java.sql.Timestamp.valueOf(startDateTime);
        dates.add(date);

        startDateTime = startDateTime.plusDays(1);
    }
    return dates;
}

你可能感兴趣的:(日期型工具类)