Java 8 Date API - Get total number of weeks in a month
问题 I have a Kotlin function to get the total number of weeks in a month Code fun getTotalWeeksInMonth(instant: Instant): Int { val calendar = Calendar.getInstance() calendar.time = Date.from(instant) return calendar.getActualMaximum(Calendar.WEEK_OF_MONTH) } However this is using a mix of the old Java date/time APIs ( Date and Calendar ) and the new APIs ( Instant ) How would I achieve the same result, using just the new APIs? 回答1: You can try something like this pair of lines: YearMonth