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

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

Description

Gets the sunday date.

License

Open Source License

Parameter

Parameter Description
week the week
year the year

Return

the sunday date

Declaration

public static java.util.Date getSundayDate(int week, int year) 

Method Source Code

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

import java.util.Calendar;

public class Main {
    /**/*  w w  w.  j  a  v  a  2 s . c  o  m*/
     * Gets the sunday date.
     * 
     * @param week the week
     * @param year the year
     * 
     * @return the sunday date
     */
    public static java.util.Date getSundayDate(int week, int year) {
        Calendar cal = getFirstSundayDateInYear(year);
        cal.add(Calendar.DAY_OF_YEAR, (week - 1) * 7);
        return cal.getTime();
    }

    /**
     * Gets the first sunday date in year.
     * 
     * @param year the year
     * 
     * @return the first sunday date in year
     */
    public static Calendar getFirstSundayDateInYear(int year) {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.DAY_OF_YEAR, 8);
        if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
            cal.set(Calendar.DAY_OF_YEAR, 7);
        int daydiff = cal.get(Calendar.DAY_OF_WEEK) - Calendar.SUNDAY;
        cal.add(Calendar.DATE, daydiff * -1);
        return cal;
    }
}

Related

  1. getScheduledDate(int dayOfWeek, int hourOfDay, int minute, int second)
  2. getSeqWeek(String date)
  3. getSeqWeekByMonth(Date currDate)
  4. getStartDate(int year, int week)
  5. getStartDates(Date baseDate, int weekNum)
  6. getSundayOfWeek(Date date)
  7. getThisweekFirst(Date early)
  8. getWeek(Date date)
  9. getWeek(Date date)