Java Day of Week getWeekDateList(Date today, int index)

Here you can find the source of getWeekDateList(Date today, int index)

Description

Gets week date list.

License

Apache License

Parameter

Parameter Description
today the today
index the index

Exception

Parameter Description

Return

ArrayList week date list

Declaration

public static ArrayList<Date> getWeekDateList(Date today, int index) 

Method Source Code

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

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

public class Main {
    /**/*from  w w  w.jav  a 2 s. c o m*/
     * Gets week date list.
     *
     * @param today the today
     * @param index the index
     * @return ArrayList<Date> week date list
     * @throws
     * @Title: getWeekDateList
     * @Description:
     */
    public static ArrayList<Date> getWeekDateList(Date today, int index) {
        ArrayList<Date> list = new ArrayList<Date>();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(today);
        if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
            calendar.add(Calendar.WEEK_OF_YEAR, -1);
        }
        calendar.add(Calendar.WEEK_OF_YEAR, index);
        calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        for (int i = 0; i <= 6; i++) {
            Calendar c = Calendar.getInstance();
            c.setTime(calendar.getTime());
            c.add(Calendar.DAY_OF_MONTH, i);
            Date d = c.getTime();
            list.add(d);
        }
        if (list.size() == 0) {
            list.add(today);
        }
        return list;
    }
}

Related

  1. getWeek(java.util.Date today)
  2. getWeekBegin(Date date)
  3. getWeekCategory(final Date date)
  4. getWeekChineseIndex(Date curDate)
  5. getWeekDate(String date)
  6. getWeekday(Date d)
  7. getWeekDay(Date d)
  8. getWeekDay(Date date)
  9. getWeekDay(Date date)