Android ThreeTenAbp 获取一年中的所有周数

Android ThreeTenAbp get all weeks of the year to array

所以我尝试使用 ThreeTenABP 库加载一年中的所有周,但我不知道从哪里开始,因为没有文档。至少我找不到。请帮帮我。

ThreeTenABP is just an Android-specific adaptation of the ThreeTen-Backport Java 项目。

ThreeTen-Backport is a back-port of the Java SE 8 date-time classes (java.time) to Java SE 6 and 7. You can find its documentation here.

来自此 answer 的代码:

private static long getNumberOfWeeksInYear(LocalDate date) {
    LocalDate middleOfYear = date.withDayOfMonth(1).withMonth(6);
    return middleOfYear.range(WeekFields.ISO.weekOfWeekBasedYear()).getMaximum();
}

您可以通过以下参数调用它:

LocalDate.of(year, 1, 1) // replace year by the the year you want, e.g. 2009