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

intgetWeekNumOfYear(Date date)
get Week Num Of Year
Calendar c = new GregorianCalendar();
c.setFirstDayOfWeek(Calendar.MONDAY);
c.setMinimalDaysInFirstWeek(7);
c.setTime(date);
return c.get(Calendar.WEEK_OF_YEAR);
StringgetWeekOfDate(Date dt)
get Week Of Date
String[] weekDays = { "7", "1", "2", "3", "4", "5", "6" };
Calendar cal = Calendar.getInstance();
cal.setTime(dt);
int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
if (w < 0)
    w = 0;
return weekDays[w];
intgetWeekOfDay(Date date)
get Week Of Day
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
if (w == 0) {
    w = Calendar.DAY_OF_WEEK;
} else if (w < 0) {
    w = 0;
return w;
intgetWeekOfMonth(Date date)
get Week Of Month
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.get(Calendar.WEEK_OF_MONTH);
intgetWeekOfMonth(final Date date)
Get the week of the month by given date.
return getNumberOfGranularity(Calendar.WEEK_OF_MONTH, date);
IntegergetWeekOfMonthFirstDay(Date dt)
get Week Of Month First Day
Calendar cal = Calendar.getInstance();
cal.set(dt.getYear() + 1900, dt.getMonth(), 1);
return cal.get(Calendar.DAY_OF_WEEK) - 1;
intgetWeekOfTheYear(Date aDate)
Week number of the date.
Calendar cal = Calendar.getInstance();
cal.setTime(aDate);
return cal.get(Calendar.WEEK_OF_YEAR);
intgetWeekOfTheYear(final Date dateOfYear)
Returns the numerical week of the year given a date.
final GregorianCalendar c = gregorianCalendarThreadLocal.get();
int minimal = c.getMinimalDaysInFirstWeek();
c.setTime(dateOfYear);
c.setMinimalDaysInFirstWeek(4);
int returnVal = c.get(Calendar.WEEK_OF_YEAR);
c.setMinimalDaysInFirstWeek(minimal); 
return returnVal;
intgetWeekOfYear(Date d, Locale locale)
get Week Of Year
Calendar c = Calendar.getInstance(getSafeLocale(locale));
c.setTime(d);
return c.get(Calendar.WEEK_OF_YEAR);
intgetWeekOfYear(Date date)
The week of the year as an int from the given Date-object.
final Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.get(Calendar.WEEK_OF_YEAR);