Java Day of Week getFirstDayOfWeek(int year, int week)

Here you can find the source of getFirstDayOfWeek(int year, int week)

Description

get First Day Of Week

License

Open Source License

Declaration

public static Date getFirstDayOfWeek(int year, int week) 

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) {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.MONTH, Calendar.JANUARY);
        cal.set(Calendar.DATE, 1);

        Calendar c = (Calendar) cal.clone();
        c.add(Calendar.DATE, week * 7);
        return getStartTimeOfWeek(c.getTime());
    }//from w  w  w . j ava  2 s.c  om

    private static Date add(Date date, int field, int amount) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(field, amount);
        return cal.getTime();
    }

    public static Date getStartTimeOfWeek(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        return cal.getTime();
    }
}

Related

  1. getDayWeekDate(String dateStr)
  2. getDayWeekDateStr(Date date)
  3. getEndOfWeek(Date date)
  4. getFirstDayOfLastWeek(Date date)
  5. getFirstDayOfWeek(int year, int week)
  6. getFirstDayOfWeek(int year, int week)
  7. getFirstDayWeekly(final int year)
  8. getFirstMonthWeek(Date month)
  9. getFirstWeekdayBetween(Date fromDate, Date toDate, int dayOfWeek)