Get first next Monday after certain date?

前端 未结 5 662
自闭症患者
自闭症患者 2020-12-01 20:56

I know there is the same question here, but I have tried the answer provided and it returned an output that I don\'t understand. I am confused by the answer and I don\'t thi

5条回答
  •  鱼传尺愫
    2020-12-01 21:34

    Or Just do some simple math. Since Calender.Monday equals 2, it is easy to calculate the number of days that need to be added to the current date.

    Calendar date1 = Calendar.getInstance();
    date1.set(2014, 05, 12);
    int dayOfWeek = date1.get(Calendar.DAY_OF_WEEK);
    date1.add(Calendar.DATE, (9 - dayOfWeek) % 7);
    

提交回复
热议问题