How to get first day of a given week number in Java

前端 未结 7 668
独厮守ぢ
独厮守ぢ 2020-12-01 12:38

Let me explain myself. By knowing the week number and the year of a date:

Date curr = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(curr);
i         


        
7条回答
  •  执笔经年
    2020-12-01 13:02

    Try this:

    public static Calendar setWeekStart(Calendar calendar) {
      while (calendar.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
        calendar.add(Calendar.DATE, -1);
      }
      setDayStart(calendar); // method which sets H:M:S:ms to 0
      return calendar;
    }
    

提交回复
热议问题