How to get the last Sunday before current date?

后端 未结 7 1182
花落未央
花落未央 2021-02-12 15:07

I have the following code for getting the last Sunday before the current date:

Calendar calendar=Calendar.getInstance();
calendar.set(Calendar.WEEK_OF_YEAR, cale         


        
7条回答
  •  伪装坚强ぢ
    2021-02-12 15:48

    final Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(cal.getTimeInMillis() //
         // Saturday is the 7th day of week, so use modulo to get it : remove day between todoay
         - (( cal.get(Calendar.DAY_OF_WEEK) % 7) * 86400000)); // 86400000=24*60*60*1000
    
    System.out.println(cal.getTime());
    . . .
    

提交回复
热议问题