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

intgetWeekOfYear(Date date)
get Week Of Year
Calendar calendar = getCalendarFromDate(date);
calendar.setFirstDayOfWeek(Calendar.MONDAY);
return calendar.get(Calendar.WEEK_OF_YEAR) - 1;
intgetWeekOfYear(Date date)
get Week Of Year
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.setFirstDayOfWeek(Calendar.SUNDAY);
cal.setMinimalDaysInFirstWeek(1);
return cal.get(Calendar.WEEK_OF_YEAR);
...
StringgetWeekOfYear(String date)
get Week Of Year
String[] tempYear = date.trim().split("-");
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, Integer.valueOf(tempYear[0]));
cal.set(Calendar.MONTH, (Integer.valueOf(tempYear[1]) - 1));
cal.set(Calendar.DATE, Integer.valueOf(tempYear[2]));
int week = cal.get(Calendar.WEEK_OF_YEAR);
return String.valueOf(week);
intgetWeeksBetweenDate(Date begin, Date end)
get Weeks Between Date
int bWeek = getDateField(begin, Calendar.WEEK_OF_YEAR);
int eWeek = getDateField(end, Calendar.WEEK_OF_YEAR);
return eWeek - bWeek;
DategetWeekStart(Date date)
Returns week start date.
if (date == null) {
    return null;
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
...
DategetWeekStart(Date date)
get Week Start
Calendar calendar = new GregorianCalendar();
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
return calendar.getTime();
...
longgetWeekStartDateBeforeCurrent(int weekNum, Date current)
get Week Start Date Before Current
Calendar calendar = Calendar.getInstance();
calendar.setTime(current);
calendar.setFirstDayOfWeek(Calendar.MONDAY);
calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
...
intgetWeekth(String sDate)
get Weekth
if (sDate == null || sDate.length() != 8)
    return -1;
Calendar c = Calendar.getInstance(Locale.KOREA);
c.set(Integer.parseInt(sDate.substring(0, 4)), Integer.parseInt(sDate.substring(4, 6)) - 1,
        Integer.parseInt(sDate.substring(6)));
GregorianCalendar gc = new GregorianCalendar(Locale.KOREA);
gc.setTime(c.getTime());
return c.get(Calendar.WEEK_OF_MONTH);
...
IntegergetYearOfWeek(Date date)
get Year Of Week
Date sunday = getSundayOfWeek(date);
return getYear(sunday);
java.util.DateincWeek(java.util.Date date, int amount, Locale locale)
inc Week
Calendar calendar = Calendar.getInstance(locale);
calendar.setTime(date);
calendar.add(Calendar.WEEK_OF_MONTH, amount);
return calendar.getTime();