If I have a specific date of a day, how do I get the date of that day in the previous week?

后端 未结 4 1736
长发绾君心
长发绾君心 2021-02-19 18:15

SEE ANSWER FROM @Basil Bourque for most up to date answer


For example, if I have a \"Date\" variable \"date1\" with a value of (dd/mm/yyy) 03/07/2011, which is a S

4条回答
  •  渐次进展
    2021-02-19 18:44

    A more clear approach:

    Calendar date = new GregorianCalendar(2011, 1, 1);
    date.add(Calendar.WEEK_OF_MONTH, -1);
    System.out.println(date.getTime());
    

    use either WEEK_OF_MONTH or WEEK_OF_YEAR

提交回复
热议问题