How to get the total number of weeks in the current year?

前端 未结 7 1828
野的像风
野的像风 2021-01-17 09:24

I got below code on stackoverflow which return total number of week in current year, but it is hardcoded which\'ll not work on 2014 and 2016. How I get total number of week

7条回答
  •  再見小時候
    2021-01-17 09:38

    You can use the Calendar.getActualMaximum(int) method to get the total number of weeks in the current year as follows:

    int totalNumberOfWeeks = Calendar.getInstance().getActualMaximum(Calendar.WEEK_OF_YEAR);
    

    Simple.

提交回复
热议问题