List of utility methods to do Week Calculate
Calendar | alignWeek(Calendar timestamp) Aligns the time fields to the start of the week. timestamp = alignDay(timestamp); int dayOfWeek = timestamp.get(Calendar.DAY_OF_WEEK); int offset = 1 - dayOfWeek; if (offset == 0) { return timestamp; return addDays(offset, timestamp); |
int | diffWeeks(Date start, Date end) Number of weeks difference between two dates if (start == null || end == null) { return -1; return (int) ((end.getTime() - start.getTime()) / (1000 * 60 * 60 * 24 * 7) + 1); |
Date[] | getBounceDatesOfWeek(Date date) get Bounce Dates Of 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 }; ... |
int | getCurrentWeekNum(Date startDate, Date endDate) get Current Week Num return 0;
|
String | getCurrWeek() get Curr Week Calendar c = Calendar.getInstance(); int w = c.get(Calendar.WEEK_OF_YEAR); if (w < 10) { return "0" + w; return String.valueOf(w); |
Calendar | getEndOfWeek(Calendar cal) Moves a calendar to the end of the week cal.add(Calendar.DAY_OF_WEEK, cal.getActualMaximum(Calendar.DAY_OF_WEEK) - cal.get(Calendar.DAY_OF_WEEK));
return cal;
|
String | getSeqWeek() get Seq Week Calendar c = Calendar.getInstance(Locale.CHINA); String week = Integer.toString(c.get(Calendar.WEEK_OF_YEAR)); if (week.length() == 1) week = "0" + week; String year = Integer.toString(c.get(Calendar.YEAR)); return year + week; |
int | getWeek(Date date) get Week Calendar c = Calendar.getInstance(); c.setTime(date); int day = c.get(Calendar.DAY_OF_WEEK); if (day == 1) { return 7; } else { return day - 1; |
Map | getWeekAbscissa(Class get Week Abscissa Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MINUTE, 0);
Date end = calendar.getTime();
calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
Date start = calendar.getTime();
Map<Date, T> week = new TreeMap<>();
...
|
int | getWeekNumberFromDate(Date date) Compute the week number of parameter date if (date != null) { Calendar calendar = Calendar.getInstance(); calendar.setFirstDayOfWeek(Calendar.MONDAY); calendar.setTime(date); return calendar.get(Calendar.WEEK_OF_YEAR); } else { return 0; |