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

intdayOfWeek(int dayMark)
day Of Week
return dayOfWeek(getYearOfDayMark(dayMark), getMonthOfDayMark(dayMark), getDayOfDayMark(dayMark));
intdayOfWeek(int year, int month, int day)
Day of week.
if (month == 1 || month == 2) {
    month += 12;
    year--;
return (day + 2 * month + 3 * (month + 1) / 5 + year + year / 4 - year / 100 + year / 400) % 7 + 1;
StringdayOfWeekFromInt(final int theDay)
Conversion utility for getting a print friendly string representation of a day of the week from a numeric between 1 and 7.
if (theDay > 7 || theDay < 1) {
    throw new IllegalArgumentException("Argument theDay is not in range of 1 to 7");
switch (theDay) {
case 1:
    return "Sunday";
case 2:
    return "Monday";
...
StringdayOfWeekFromInteger(String aDay, boolean longName)
day Of Week From Integer
if (aDay == "1") {
    return longName ? "Sunday" : "Sun";
if (aDay == "2") {
    return longName ? "Monday" : "Mon";
if (aDay == "3") {
    return longName ? "Tuesday" : "Tue";
...
String[]dayOfWeekNames()
Public method dayOfWeekNames() returns an array of the names for days of a week in the default locale.
return dayOfWeekNames;
CalendarendOfWeek(Date inDate, TimeZone timeZone)
Calculate the start of the week for the given date.
Calendar c1 = Calendar.getInstance(timeZone);
c1.setTime(inDate);
Calendar c2 = Calendar.getInstance(timeZone);
c2.clear();
int daysToAdd = 8 - isoDayOfWeek(c1.get(Calendar.DAY_OF_WEEK));
c2.set(c1.get(Calendar.YEAR), c1.get(Calendar.MONTH), c1.get(Calendar.DAY_OF_MONTH) + daysToAdd);
return c2;
intextractDayOfWeek(Date date)
Extract the day of the week from a Date instance.
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal.get(Calendar.DAY_OF_WEEK);
DayOfWeekfindDayOfWeek(String threeLetters)
find Day Of Week
for (DayOfWeek dow : DayOfWeek.values()) {
    if (threeLetters.equals(dow.getDisplayName(TextStyle.SHORT, Locale.ENGLISH))) {
        return dow;
return null;
DatefirstDateAfterAddWeeks(Date early, int weeks)
first Date After Add Weeks
Date firstDate = getThisweekFirst(early);
firstDate = dayAdd(firstDate, weeks * 7);
return firstDate;
TemporalAdjusterfirstDayOfWeek()
java.time.temporal.TemporalAdjuster to select the first day of the week from a java.time.OffsetDateTime object.
return t -> t.with(DAY_OF_WEEK, 1);