Java Utililty Methods Week Day

List of utility methods to do Week Day

Description

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

Method

intgetDayOfWeek(Date date)
get Day Of Week
return getField(date, Locale.getDefault(), Calendar.DAY_OF_WEEK);
intgetDayOfWeek(Date date)
get Day Of Week
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(date.getTime());
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
int rel = 0;
switch (dayOfWeek) {
case Calendar.MONDAY:
    rel = 1;
    break;
...
StringgetDayOfWeek(Date date)
get Day Of Week
String[] weekDays = { "SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY" };
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
if (w < 0)
    w = 0;
return weekDays[w];
StringgetDayOfWeek(Date date)
Gets the day of the week for the specified date.
String dayOfWeek = null;
Calendar c = Calendar.getInstance(Locale.US);
c.setTime(date);
switch (c.get(Calendar.DAY_OF_WEEK)) {
case Calendar.MONDAY:
    dayOfWeek = "Monday";
    break;
case Calendar.TUESDAY:
...
intgetDayOfWeek(Date date)
get Day Of Week
return getField(date, Calendar.DAY_OF_WEEK);
DategetDayOfWeek(Date date, int day)
get Day Of Week
Calendar c = new GregorianCalendar();
c.setFirstDayOfWeek(Calendar.MONDAY);
c.setTime(date);
c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek() + day - 1);
return c.getTime();
StringgetDayOfWeek(Date dt)
Get and return the day of week from the given Date dt
Calendar cal = new GregorianCalendar();
cal.setTime(dt);
int dow = cal.get(Calendar.DAY_OF_WEEK);
switch (dow) {
case 1:
    return "SUN";
case 2:
    return "MON";
...
DategetDayOfWeek(Date start, int day)
Method to get day number of week.
if (day == 0)
    return start;
Calendar calendar = Calendar.getInstance();
calendar.setTime(start);
calendar.add(Calendar.DAY_OF_YEAR, day);
return calendar.getTime();
intgetDayOfWeek(int _year, int _month, int _day)
get Day Of Week
int year, month, date;
Calendar cal = Calendar.getInstance();
cal.set(_year, _month - 1, _day);
return cal.get(Calendar.DAY_OF_WEEK);
intgetDayOfWeek(int year, int month, int day)
get Day Of Week
Calendar calendar = Calendar.getInstance();
if (year > -1) {
    calendar.set(Calendar.YEAR, year);
if (month > -1) {
    month--;
    calendar.set(Calendar.MONTH, month);
if (day > -1) {
    calendar.set(Calendar.DAY_OF_MONTH, day);
return calendar.get(Calendar.DAY_OF_WEEK);