Java Day of Week getWeekBegin(Date date)

Here you can find the source of getWeekBegin(Date date)

Description

get Week Begin

License

Open Source License

Declaration

public static Date getWeekBegin(Date date) 

Method Source Code

//package com.java2s;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main {
    public static Date getWeekBegin(Date date) {
        if (date == null) {
            return null;
        }//from ww w .  j  ava  2 s . c om
        Calendar cal = new GregorianCalendar();
        cal.setTime(date);

        int dw = cal.get(Calendar.DAY_OF_WEEK);
        while (dw != Calendar.MONDAY) {
            cal.add(Calendar.DATE, -1);
            dw = cal.get(Calendar.DAY_OF_WEEK);
        }
        return cal.getTime();
    }

    public static Date getWeekBegin(Calendar calendar) {
        if (calendar == null) {
            return null;
        }

        Calendar date = new GregorianCalendar(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
                calendar.get(Calendar.DAY_OF_MONTH));

        int dw = date.get(Calendar.DAY_OF_WEEK);
        while (dw != Calendar.MONDAY) {
            date.add(Calendar.DATE, -1);
            dw = date.get(Calendar.DAY_OF_WEEK);
        }

        return date.getTime();
    }
}

Related

  1. getWeek(Date date)
  2. getWeek(Date dateParam)
  3. getWeek(Date today)
  4. getWeek(java.util.Date date)
  5. getWeek(java.util.Date today)
  6. getWeekCategory(final Date date)
  7. getWeekChineseIndex(Date curDate)
  8. getWeekDate(String date)
  9. getWeekDateList(Date today, int index)