Is there a good way to get the date of the coming Wednesday?

Viewed 16740

Is there a good way to get the date of the coming Wednesday? That is, if today is Tuesday, I want to get the date of Wednesday in this week; if today is Wednesday, I want to get the date of next Wednesday; if today is Thursday, I want to get the date of Wednesday in the following week.

Thanks.

6 Answers
public static void nextWednesday() throws ParseException 
    {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        int weekday = calendar.get(Calendar.DAY_OF_WEEK);
        int days = Calendar.WEDNESDAY - weekday;
        if (days < 0)
        {
            days += 7;
        }
        calendar.add(Calendar.DAY_OF_YEAR, days);

        System.out.println(sdf.format(calendar.getTime()));
    }
Related