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

booleanisWeekendToday()
is Weekend Today
Calendar calendar = Calendar.getInstance();
int week = calendar.get(Calendar.DAY_OF_WEEK);
return week == 1 || week == 7;
intlastDayOfWeek(int year, int month)
last Day Of Week
Date lastDate = new Date(year - 1900, month - 1, days(year, month));
return lastDate.getDay();
DatenextDayAndHour(int dayOfTheWeek, int hour)
next Day And Hour
Calendar cal = new GregorianCalendar();
cal.setTimeInMillis(System.currentTimeMillis());
if (cal.get(Calendar.DAY_OF_WEEK) > dayOfTheWeek
        || (cal.get(Calendar.DAY_OF_WEEK) == dayOfTheWeek && cal.get(Calendar.HOUR_OF_DAY) >= hour)) {
    cal.add(Calendar.WEEK_OF_YEAR, 1);
cal.set(Calendar.DAY_OF_WEEK, dayOfTheWeek);
cal.set(Calendar.HOUR_OF_DAY, hour);
...
DatenextTwoWeeksFromToday()
next Two Weeks From Today
return addDays(new Date(), 14);
DatenextWeekday(int weekday, int hour, int minute, int second)
next Weekday
Calendar now = now();
int day = now.get(Calendar.DAY_OF_MONTH) + (7 - now.get(Calendar.DAY_OF_WEEK)) + weekday;
return year(now.get(Calendar.MONTH), day, hour, minute, second);
StringparseToEntireWeekCaption(String startDay, String pattern)
parse To Entire Week Caption
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
Calendar calendar = new GregorianCalendar(2012, Calendar.JANUARY, 1);
calendar.setTime(sdf.parse(startDay));
calendar.add(Calendar.DAY_OF_MONTH, 6);
String endDay = sdf.format(calendar.getTime());
return startDay + "~" + endDay;
DateplusDay(Date date, int plusWeek)
plus Day
return plusInteger(date, Calendar.DAY_OF_MONTH, plusWeek);
voidtoDayOfWeekInMonth(Calendar c, int dayOfWeek, int weekInMonth)
Takes you to eg the 2nd Thursday in the month, which may involve going back before the current date
c.set(Calendar.DATE, 1);
c.set(Calendar.DAY_OF_WEEK, dayOfWeek);
c.set(Calendar.DAY_OF_WEEK_IN_MONTH, weekInMonth);
DateweekDay(int week)
week Day
Calendar cal = calendar();
cal.set(Calendar.DAY_OF_WEEK, week);
return cal.getTime();
Stringweekday(String date)
weekday
Calendar calendar = Calendar.getInstance();
DateFormat dateFormat = DateFormat.getDateInstance();
Date da = null;
da = dateFormat.parse(date);
calendar.setTime(da);
int num = calendar.get(Calendar.DAY_OF_WEEK);
if (num == 1) {
    num = 7;
...