List of utility methods to do Day of Week
List | getAllDaysDateBetween(Date startDate, Date endDate, DayOfWeek dayOfWeek) get All Days Date Between Calendar startCal = Calendar.getInstance(); startCal.setTime(startDate); Calendar endCal = Calendar.getInstance(); endCal.setTime(endDate); ArrayList<Date> daysDateList = new ArrayList<>(); while (!startCal.equals(endCal)) { startCal.add(Calendar.DATE, 1); if (startCal.get(Calendar.DAY_OF_WEEK) == dayOfWeek.getValue()) { ... |
Date[] | getBounceDateofWeek(Date date) get Bounce Dateof Week Calendar calendar = new GregorianCalendar(); calendar.setFirstDayOfWeek(Calendar.MONDAY); calendar.setTime(date); calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); Date begin = calendar.getTime(); calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); Date end = calendar.getTime(); return new Date[] { begin, end }; ... |
Date | getDateByWeek(int week) get Date By Week Calendar cal = Calendar.getInstance(); int nowWeek = cal.get(Calendar.DAY_OF_WEEK); if (nowWeek == Calendar.SUNDAY) { nowWeek = 6; } else { nowWeek -= 2; return getDateByDaysLate(week - nowWeek, cal.getTime()); ... |
Date | getDateByYearAndWeekNum(int year, int weekNum) get Date By Year And Week Num Calendar c = new GregorianCalendar(); c.set(Calendar.YEAR, year); c.set(Calendar.WEEK_OF_YEAR, weekNum); return c.getTime(); |
Date | getDateForCurrentWeekDay(int day) get Date For Current Week Day Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.clear(Calendar.MINUTE);
cal.clear(Calendar.SECOND);
cal.clear(Calendar.MILLISECOND);
cal.set(Calendar.DAY_OF_WEEK, day);
return cal.getTime();
|
Date | getDateOfWeek(int week) get Date Of Week return getDateOfWeek(new Date(), week); |
Date | getDateOfWeek(int year, int weekOfYear, int i) get Date Of Week Calendar day = getCalendar(); day.set(Calendar.YEAR, year); day.set(Calendar.WEEK_OF_YEAR, weekOfYear + 1); day.setFirstDayOfWeek(FIRST_DAY_OF_WEEK); switch (i) { case 0: day.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); break; ... |
Date | getDateOfYearWeek(int yearNum, int weekNum, int dayOfWeek) get Date Of Year Week Calendar cal = Calendar.getInstance();
cal.setFirstDayOfWeek(Calendar.MONDAY);
cal.set(Calendar.DAY_OF_WEEK, dayOfWeek);
cal.setMinimalDaysInFirstWeek(DAYS_OF_A_WEEK);
cal.set(Calendar.YEAR, yearNum);
cal.set(Calendar.WEEK_OF_YEAR, weekNum);
return cal.getTime();
|
int | getDateWeek(String date) get Date Week Calendar calendar = toCalendar(date + " 00:00:01"); int week = calendar.get(Calendar.DAY_OF_WEEK); week = week - 1; if (week == 0) week = 7; return week; |
long | getDay(long date, int startOfWeek, int increment) get Day Calendar calendar = CALENDAR; synchronized (calendar) { calendar.setTimeInMillis(date); int day = calendar.get(Calendar.DAY_OF_WEEK); while (day != startOfWeek) { calendar.add(Calendar.DATE, increment); day = calendar.get(Calendar.DAY_OF_WEEK); return startOfDayInMillis(calendar.getTimeInMillis()); |