Java Day of Week getDateByWeek(int week)

Here you can find the source of getDateByWeek(int week)

Description

get Date By Week

License

Open Source License

Declaration

public static Date getDateByWeek(int week) 

Method Source Code

//package com.java2s;

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

public class Main {

    public static Date getDateByWeek(int week) {
        Calendar cal = Calendar.getInstance();
        int nowWeek = cal.get(Calendar.DAY_OF_WEEK);
        if (nowWeek == Calendar.SUNDAY) {
            nowWeek = 6;// w  ww  . j a v  a  2s.c o  m
        } else {
            nowWeek -= 2;
        }
        return getDateByDaysLate(week - nowWeek, cal.getTime());
    }

    public static Date getDateByDaysLate(int day, Date date) {
        Calendar todayStart = Calendar.getInstance();
        if (date != null) {
            todayStart.setTime(date);
        }
        todayStart.set(Calendar.HOUR_OF_DAY, 0);
        todayStart.set(Calendar.MINUTE, 0);
        todayStart.set(Calendar.SECOND, 0);
        todayStart.set(Calendar.MILLISECOND, 0);
        todayStart.add(Calendar.DATE, day);
        return todayStart.getTime();
    }
}

Related

  1. findDayOfWeek(String threeLetters)
  2. firstDateAfterAddWeeks(Date early, int weeks)
  3. firstDayOfWeek()
  4. getAllDaysDateBetween(Date startDate, Date endDate, DayOfWeek dayOfWeek)
  5. getBounceDateofWeek(Date date)
  6. getDateByYearAndWeekNum(int year, int weekNum)
  7. getDateForCurrentWeekDay(int day)
  8. getDateOfWeek(int week)
  9. getDateOfWeek(int year, int weekOfYear, int i)