Java Utililty Methods Day of Week

List of utility methods to do Day of Week

Description

The list of methods to do Day of Week are organized into topic(s).

Method

IntegergetWeek(Date date)
get Week
if (date == null)
    return null;
Calendar c = Calendar.getInstance();
c.setTime(date);
return chweek[c.get(Calendar.DAY_OF_WEEK)];
intgetWeek(Date dateParam)
get Week
if (dateParam == null) {
    throw new IllegalArgumentException("The dateParam  must not be null");
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(dateParam.getTime());
return cal.get(Calendar.WEEK_OF_YEAR);
intgetWeek(Date today)
get Week
Calendar calendar = Calendar.getInstance();
calendar.setTime(today);
switch (calendar.get(Calendar.DAY_OF_WEEK)) {
case 1:
    return 0;
case 2:
    return 1;
case 3:
...
intgetWeek(java.util.Date date)
get Week
java.util.Calendar c = java.util.Calendar.getInstance();
c.setTime(date);
int dayOfWeek = c.get(java.util.Calendar.DAY_OF_WEEK);
dayOfWeek = dayOfWeek - 1;
if (dayOfWeek == 0) {
    dayOfWeek = Calendar.DAY_OF_WEEK;
return dayOfWeek;
...
IntegergetWeek(java.util.Date today)
getWeek: returns the week of the date
if (today != null) {
    java.util.Calendar c = java.util.Calendar.getInstance(Locale.GERMANY);
    c.setTime(today);
    return c.get(Calendar.WEEK_OF_YEAR);
} else {
    return null;
DategetWeekBegin(Date date)
get Week Begin
if (date == null) {
    return null;
Calendar cal = new GregorianCalendar();
cal.setTime(date);
int dw = cal.get(Calendar.DAY_OF_WEEK);
while (dw != Calendar.MONDAY) {
    cal.add(Calendar.DATE, -1);
...
StringgetWeekCategory(final Date date)
get Week Category
String week = String.valueOf(createDate(date).get(Calendar.WEEK_OF_YEAR));
if (week.length() == 1) {
    week = "0" + week; 
return week;
intgetWeekChineseIndex(Date curDate)
get Week Chinese Index
Calendar c = Calendar.getInstance();
c.setTime(curDate);
int i = c.get(Calendar.DAY_OF_WEEK);
int s = 0;
if (i == 1) {
    s = 7;
} else {
    s = i - 1;
...
String[]getWeekDate(String date)
get Week Date
String[] weekDays = new String[7];
weekDays[0] = getMondayDate(date);
weekDays[1] = getWeekDays(weekDays[0], 1);
weekDays[2] = getWeekDays(weekDays[0], 2);
weekDays[3] = getWeekDays(weekDays[0], 3);
weekDays[4] = getWeekDays(weekDays[0], 4);
weekDays[5] = getWeekDays(weekDays[0], 5);
weekDays[6] = getWeekDays(weekDays[0], 6);
...
ArrayListgetWeekDateList(Date today, int index)
Gets week date list.
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);
...