Java Day of Week weekStart(Date date)

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

Description

week Start

License

GNU General Public License

Declaration

public static Date weekStart(Date date) 

Method Source Code


//package com.java2s;
/*//from   w w  w.ja  va 2  s .  c  om
 * Copyright (C) 2009-2014 StackFrame, LLC
 * This code is licensed under GPLv2.
 */

import java.util.Calendar;

import java.util.Date;

public class Main {
    public static Date weekStart(Date date) {
        Calendar startDate = Calendar.getInstance();
        startDate.setTime(date);

        // Roll back to previous Saturday if not already on a Saturday.
        int day = startDate.get(Calendar.DAY_OF_WEEK);
        if (day != Calendar.SATURDAY) {
            startDate.add(Calendar.DATE, -day);
        }

        return startDate.getTime();
    }
}

Related

  1. weekDaysBetween(final Date a, final Date b)
  2. WeekOfTheYear(Date dt)
  3. weekOfYear(Date date)
  4. weeksBetween(Date date1, Date date2)
  5. weeksBetween(Date early, Date late)
  6. weekStart(Date date)