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

intcalculateBusinessDays(Date startDate, Date endDate, int firstWeekendDay, int secondWeekendDay)
calculate Business Days
Calendar startCal = Calendar.getInstance();
startCal.setTime(startDate);
Calendar endCal = Calendar.getInstance();
endCal.setTime(endDate);
int workDays = 0;
if (startCal.getTimeInMillis() == endCal.getTimeInMillis()) {
    return 0;
if (startCal.getTimeInMillis() > endCal.getTimeInMillis()) {
    startCal.setTime(endDate);
    endCal.setTime(startDate);
do {
    startCal.add(Calendar.DAY_OF_MONTH, 1);
    if (startCal.get(Calendar.DAY_OF_WEEK) != firstWeekendDay
            && startCal.get(Calendar.DAY_OF_WEEK) != secondWeekendDay) {
        workDays++;
} while (startCal.getTimeInMillis() <= endCal.getTimeInMillis());
return workDays;
StringDay_Of_Week(String Date, int DayCase)
Da O Week
StringBuffer dow = new StringBuffer(
        DOW[(int) (Math.floor((Cal_Julian(Date) + 2) - (Math.floor((Cal_Julian(Date) + 2) / 7) * 7)))]);
if ((DayCase == 1) || (DayCase == 2) || (DayCase == 3))
    dow = new StringBuffer(dow.substring(0, 3));
switch (DayCase) {
case 1:
case 4:
    return dow.toString().toUpperCase();
...
intdayForWeek(String pTime)
day For Week
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
Calendar c = Calendar.getInstance();
int dayForWeek = 0;
try {
    c.setTime(format.parse(pTime));
    if (c.get(Calendar.DAY_OF_WEEK) == 1) {
        dayForWeek = 7;
    } else {
...
intdayForWeek(String pTime)
day For Week
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
try {
    c.setTime(format.parse(pTime));
} catch (ParseException e) {
    e.printStackTrace();
int dayForWeek = 0;
...
ListdayForWeek(String weeks)
day For Week
List<String> retDates = new ArrayList<String>();
int day = 1;
SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd");
while (retDates.size() < 4) {
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, day);
    if (weeks.contains(String.valueOf(cal.get(Calendar.DAY_OF_WEEK) - 1))) {
        System.out.println(cal.get(Calendar.DAY_OF_WEEK) - 1);
...
intdayNumberOfWeek(Date date)
Day Number
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal.get(Calendar.DAY_OF_WEEK);
intDayOfTheWeek(Date dt)
Day Of The Week
Calendar cal = new GregorianCalendar();
cal.setTime(dt);
return cal.get(Calendar.DAY_OF_WEEK); 
intdayOfWeek(Date date)
day Of Week
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int dayWeek = cal.get(Calendar.DAY_OF_WEEK);
return dayWeek;
intdayOfWeek(Date inDate, TimeZone timeZone)
Calculate the day number for the given date.
Calendar calendar = Calendar.getInstance(timeZone);
calendar.setTime(inDate);
return calendar.get(Calendar.DAY_OF_WEEK);
intdayOfWeek(Date time)
day Of Week
Calendar c = Calendar.getInstance();
c.setTime(time);
int dayForWeek = 0;
if (c.get(Calendar.DAY_OF_WEEK) == 1) {
    dayForWeek = 7;
} else {
    dayForWeek = c.get(Calendar.DAY_OF_WEEK) - 1;
return dayForWeek;