Java Day of Week getSundayOfWeek(Date date)

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

Description

get Sunday Of Week

License

Apache License

Declaration

public static Date getSundayOfWeek(Date date) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public static int FIRST_DAY_OF_WEEK = Calendar.MONDAY;

    public static Date getSundayOfWeek(Date date) {
        Calendar sunday = getCalendar();
        sunday.setTime(date);//from www .j  av  a2  s. co  m
        sunday.setFirstDayOfWeek(FIRST_DAY_OF_WEEK);
        sunday.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
        return sunday.getTime();
    }

    public static Date getSundayOfWeek(int year, int weekOfYear) {
        Calendar sunday = getCalendar();
        sunday.set(Calendar.YEAR, year);
        sunday.set(Calendar.WEEK_OF_YEAR, weekOfYear + 1);
        sunday.setFirstDayOfWeek(FIRST_DAY_OF_WEEK);
        sunday.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
        return sunday.getTime();
    }

    private static Calendar getCalendar() {
        Calendar c = Calendar.getInstance();
        c.setFirstDayOfWeek(FIRST_DAY_OF_WEEK);
        return c;
    }
}

Related

  1. getSeqWeek(String date)
  2. getSeqWeekByMonth(Date currDate)
  3. getStartDate(int year, int week)
  4. getStartDates(Date baseDate, int weekNum)
  5. getSundayDate(int week, int year)
  6. getThisweekFirst(Date early)
  7. getWeek(Date date)
  8. getWeek(Date date)
  9. getWeek(Date dateParam)