Java Time: Get max number of weeks for particular year

后端 未结 4 966

I only found a solution for Joda Time.

My solution works only if the last day is not in the first week:

LocalDate.now() // or any other LocalDate
  .         


        
4条回答
  •  感情败类
    2020-12-21 08:47

    It seems that when the last day is in the first week, you don't want to get 1 as an answer but 52/3/4, in which case you may be looking for:

    LocalDate.of(2017, 12, 31).get(WeekFields.ISO.weekOfYear());
    

    There are several ways to define week numbers - if that doesn't do what you want you need to clarify which method you want to use.

提交回复
热议问题