Get week of month with Joda-Time

前端 未结 4 463
半阙折子戏
半阙折子戏 2021-01-12 20:00

Is it possible to parse a date and extract the week of month using Joda-Time. I know it is possible to do it for the week of year but I cannot find how/if it is possible to

4条回答
  •  遥遥无期
    2021-01-12 20:43

    If the start day of week is Monday then you can use it:

    public int getWeekOfMonth(DateTime date){
        DateTime.Property dayOfWeeks = date.dayOfWeek();
        return (int) (Math.ceil((date.dayOfMonth().get() - dayOfWeeks.get()) / 7.0)) + 1;
    }
    

提交回复
热议问题