Java Week Day isDayOfWeek(String str, int dayOfWeek)

Here you can find the source of isDayOfWeek(String str, int dayOfWeek)

Description

is Day Of Week

License

Open Source License

Declaration


public static boolean isDayOfWeek(String str, int dayOfWeek) 

Method Source Code

//package com.java2s;

import java.util.Calendar;
import java.util.Date;

public class Main {

    public static boolean isDayOfWeek(String str, int dayOfWeek) {
        int day = getCalendar(str).get(Calendar.DAY_OF_WEEK);
        if (day == dayOfWeek)
            return true;
        else/*from   w w w. ja  v  a 2 s .c o  m*/
            return false;
    }

    public static boolean isDayOfWeek(Date date, int dayOfWeek) {
        int day = getCalendar(date).get(Calendar.DAY_OF_WEEK);
        if (day == dayOfWeek)
            return true;
        else
            return false;
    }

    public static Calendar getCalendar(String str) {
        int yy = Integer.parseInt(str.substring(0, 4));
        int mm = Integer.parseInt(str.substring(4, 6)) - 1;
        int dd = Integer.parseInt(str.substring(6, 8));

        Calendar cal = Calendar.getInstance();
        cal.set(yy, mm, dd);
        return cal;
    }

    public static Calendar getCalendar(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        return cal;
    }
}

Related

  1. getWeekdays(DateFormatSymbols symbols)
  2. getWeekDayStr(int dayInWeek)
  3. getWeekendDays(Locale locale)
  4. getWeekFirstDay(Date date)
  5. isDayOfWeek(int day)
  6. isFirseDayOfCurrentWeek(Date date)
  7. isoDayOfWeek(int javaDayOfWeek)
  8. isWeekday(String dateStr, String format)
  9. isWeekendDay(String strDay, DateFormat dateFormatter)