Joda-Time: Get max number of weeks for particular year

前端 未结 3 1720
没有蜡笔的小新
没有蜡笔的小新 2021-02-15 17:31

How do I get the maximum number of weeks for a particular year with Joda-Time?

3条回答
  •  梦如初夏
    2021-02-15 18:27

    new DateTime().withYear(PARTICULAR_YEAR).weekOfWeekyear().getMaximumValue();
    

    @cody Comment

    Difference between the two methods .withWeekOfWeekyear() and .withWeekyear()

    Example

    new DateTime().withDate(2011, 1, 2);   
    

    2/1/2011       : Sunday, last day of last week of 2010 (27/12/2010 - 2/1/2011)   
    dayOfWeek      : 7
    weekOfWeekyear : 52  
    weekyear       : 2010
    


    new DateTime().withDate(2011, 1, 3);
    

    3/1/2011       : Monday, first day of first week of 2011 (3/1/2011 - 9/1/2011)
    dayOfWeek      : 1
    weekOfWeekyear : 1
    weekyear       : 2011
    

提交回复
热议问题