Java Week End getFirstDayOfWeek(Date date)

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

Description

get First Day Of Week

License

Open Source License

Declaration

public static Date getFirstDayOfWeek(Date date) 

Method Source Code

//package com.java2s;

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

public class Main {

    public static Date getFirstDayOfWeek(int year, int week) {
        week = week - 1;//from  w w w  .  j  a  va  2s  .com
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.YEAR, year);
        calendar.set(Calendar.MONTH, Calendar.JANUARY);
        calendar.set(Calendar.DATE, 1);

        Calendar cal = (Calendar) calendar.clone();
        cal.add(Calendar.DATE, week * 7);

        return getFirstDayOfWeek(cal.getTime());
    }

    public static Date getFirstDayOfWeek(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setFirstDayOfWeek(Calendar.SUNDAY);
        calendar.setTime(date);
        calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek()); // Sunday
        return calendar.getTime();
    }
}

Related

  1. getFirstDayOfWeek(Date date)
  2. getFirstDayOfWeek(Date date)
  3. getFirstDayOfWeek(Date date)
  4. getFirstDayOfWeekFromMonday(Date now)