How to get the last Sunday before current date?

后端 未结 7 1199
花落未央
花落未央 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 16:05

    The following works for me irrespective of which month and year.

     Calendar cal = Calendar.getInstance(TimeZone.getDefault());
     Date date = cal.getTime();
     int days = cal.get(Calendar.DAY_OF_WEEK) - Calendar.SUNDAY;
     date.setTime(date.getTime() - (long) (days*1000*60*60*24));
     cal.setTime(date);
    
    0 讨论(0)
提交回复
热议问题