Java Day of Week getWeekStart(Date date)

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

Description

get Week Start

License

Open Source License

Declaration

public static Date getWeekStart(Date date) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static Date getWeekStart(Date date) {
        // get a calendar corresponding to the current date
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);/* w  ww .j  av a 2  s.c  o  m*/
        // set to midnight
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        // set to previous monday
        calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        // return monday at midnight
        return calendar.getTime();
    }
}

Related

  1. getWeekOfYear(Date date)
  2. getWeekOfYear(Date date)
  3. getWeekOfYear(String date)
  4. getWeeksBetweenDate(Date begin, Date end)
  5. getWeekStart(Date date)
  6. getWeekStartDateBeforeCurrent(int weekNum, Date current)
  7. getWeekth(String sDate)
  8. getYearOfWeek(Date date)
  9. incWeek(java.util.Date date, int amount, Locale locale)