Java Week Day getMonday(String date, int weekDay)

Here you can find the source of getMonday(String date, int weekDay)

Description

get Monday

License

Apache License

Declaration

public static Date getMonday(String date, int weekDay) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {

    public static Date getMonday(String date, int weekDay) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date d = null;//w w  w .  j  ava 2s.com
        try {
            d = format.parse(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        Calendar cal = Calendar.getInstance();
        if (d != null) {
            cal.setTime(d);
        }
        // DAY_OF_WEEK
        // Field number for get and set indicating
        // the day of the week. This field takes values
        // SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY,
        // and SATURDAY
        cal.set(Calendar.DAY_OF_WEEK, weekDay);
        cal.add(Calendar.DATE, 1);
        return cal.getTime();
    }
}

Related

  1. getLastWeekDay(int weekDay)
  2. getLastWeekDay(int weekDay)
  3. getLastWeekMs()
  4. getMon()
  5. getMonday(String date)
  6. getMondayAfter(Date date)
  7. getMondayOfThisWeek()
  8. getNextDayOfweek()
  9. getPreDay()