List of utility methods to do Year Week
String | getEndDayByWeekOfYear(int year, int weekNo) get the end day of given week no of a year.,the first day of week is Sunday Calendar cal = getCalendarFormYear(year); cal.set(Calendar.WEEK_OF_YEAR, weekNo); cal.add(Calendar.DAY_OF_WEEK, 6); int monthInt = cal.get(Calendar.MONTH) + 1; String monthString = monthInt < 10 ? "0" + monthInt : monthInt + ""; int dayOfMontyInt = cal.get(Calendar.DAY_OF_MONTH); String dayOfMonth = dayOfMontyInt < 10 ? "0" + dayOfMontyInt : dayOfMontyInt + ""; return cal.get(Calendar.YEAR) + "-" + monthString + "-" + dayOfMonth; ... |
Date | getLastDayOfWeek(int year, int week) get Last Day Of Week Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, Calendar.JANUARY);
cal.set(Calendar.DATE, 1);
Calendar c = (Calendar) cal.clone();
c.add(Calendar.DATE, week * 7);
return getEndTimeOfWeek(c.getTime());
|
String | getLastWeekOfYear() get Last Week Of Year int num = Calendar.getInstance().get(Calendar.WEEK_OF_YEAR); if (num > 1) { num--; return (num + "").length() == 1 ? "0" + num : "" + num; |
int | getMaxWeekNumOfYear(int year) get Max Week Num Of Year Calendar c = new GregorianCalendar(); c.set(year, Calendar.DECEMBER, 31, 23, 59, 59); return getWeekOfYear(c.getTime()); |
Date | getNextWeekMonday(int year, int weekOfYear) get Next Week Monday Date date = getMondayOfWeek(year, weekOfYear);
return getNextWeekDate(date);
|
int | getNumberOfWeeksInYear(int year) Computes the number of weeks in a given year See: http://stackoverflow.com/questions/18438332/how-to-get-total-number-of-week-in-the-current-year GregorianCalendar cal = new GregorianCalendar(year, 12, 31); cal.setFirstDayOfWeek(Calendar.MONDAY); cal.setMinimalDaysInFirstWeek(4); return cal.getMaximum(Calendar.WEEK_OF_YEAR); |
int | getSeasonStartWeekOffset(int year) get Season Start Week Offset Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, Calendar.SEPTEMBER); cal.set(Calendar.DAY_OF_MONTH, 1); switch (cal.get(Calendar.DAY_OF_WEEK)) { case Calendar.SUNDAY: return 34; case Calendar.MONDAY: ... |
String | getStartDayOfWeekNo(int year, int weekNo) get start date of given week no of a year Calendar cal = getCalendarFormYear(year); cal.set(Calendar.WEEK_OF_YEAR, weekNo); return cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH) + 1) + "-" + cal.get(Calendar.DAY_OF_MONTH); |
int | getTotalWeekOfYear(int year) get Total Week Of Year Calendar c = Calendar.getInstance();
return c.getActualMaximum(Calendar.WEEK_OF_YEAR);
|
String | getYmd(int year, int week, int days) get Ymd Calendar calendar = Calendar.getInstance(); if (year > 0) { calendar.set(Calendar.YEAR, year); calendar.set(Calendar.WEEK_OF_YEAR, week); calendar.set(Calendar.DAY_OF_WEEK, days); int month = calendar.get(Calendar.MONTH) + 1; int day = calendar.get(Calendar.DAY_OF_MONTH); ... |