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

intWeekOfTheYear(Date dt)
Settimana dell'anno
Calendar cal = new GregorianCalendar();
cal.setTime(dt);
return cal.get(Calendar.WEEK_OF_YEAR);
StringweekOfYear(Date date)
week Of Year
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH) + 1;
int day = cal.get(Calendar.DATE);
int a, b, c, s, e, f, g, d, n;
int week;
if (month <= 2) {
...
intweeksBetween(Date date1, Date date2)
weeks Between
int days = daysBetween(date1, date2);
return (days % 7) == 0 ? (days / 7) : (days / 7) + 1;
intweeksBetween(Date early, Date late)
Returns the weeks between two dates.
Calendar c1 = Calendar.getInstance();
Calendar c2 = Calendar.getInstance();
c1.setTime(early);
c2.setTime(late);
int days = daysBetween(c1, c2) + 1;
int earlyweek = c1.get(Calendar.DAY_OF_WEEK);
int lateweek = c2.get(Calendar.DAY_OF_WEEK);
int weeks = days / 7;
...
DateweekStart(Date date)
week Start
Calendar startDate = Calendar.getInstance();
startDate.setTime(date);
int day = startDate.get(Calendar.DAY_OF_WEEK);
if (day != Calendar.SATURDAY) {
    startDate.add(Calendar.DATE, -day);
return startDate.getTime();
DateweekStart(Date date)
week Start
if (date == null) {
    return null;
Calendar calendar = Calendar.getInstance();
calendar.setTime(dateStart(date));
calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek());
return calendar.getTime();