Java Utililty Methods Week Day

List of utility methods to do Week Day

Description

The list of methods to do Week Day are organized into topic(s).

Method

String[]getBothDayOfWeek(String str, int week)
get Both Day Of Week
return new String[] { getFirstDayOfWeek(str, week), getLastDayOfWeek(str, week) };
intgetCurrentDayOfWeekArabia()

Method: get current day of week in Arabia return type int

Calendar calendar = Calendar.getInstance(Locale.getDefault());
return calendar.get(Calendar.DAY_OF_WEEK);
StringgetCurrentDayOfWeekEnglish()

Method: get current day of week in English return type String

String[] dayOfWeek = { "Sunday", "Monday", "Tuseday", "Wednesday", "Thursday", "Friday", "Saturday" };
return dayOfWeek[getCurrentDayOfWeekArabia() - 1];
intgetCurWeek(String day)
get Cur Week
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date date = null;
if (day != null) {
    try {
        date = format.parse(day);
    } catch (ParseException e) {
        e.printStackTrace();
} else {
    date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setFirstDayOfWeek(Calendar.MONDAY);
calendar.setTime(date);
return calendar.get(Calendar.WEEK_OF_YEAR);
intgetCurWeekDayByStr(String curday)
get Cur Week Day By Str
try {
    java.util.Date date = str2date(curday);
    Calendar rightNow = Calendar.getInstance();
    rightNow.setTime(date);
    return rightNow.get(Calendar.DAY_OF_WEEK);
} catch (Exception e) {
    e.printStackTrace();
    return 1;
...
intgetCurWeekDayByStr(String curday)
get Cur Week Day By Str
try {
    java.util.Date date = str2utilDate(curday);
    Calendar rightNow = Calendar.getInstance();
    rightNow.setTime(date);
    int week = rightNow.get(Calendar.DAY_OF_WEEK);
    return week;
} catch (Exception e) {
    System.out.println("DateUtil.getYearWeek(str) Error:e = " + e);
...
longgetDay(long date, int startOfWeek, int increment)
get Day
Calendar calendar = CALENDAR;
synchronized (calendar) {
    calendar.setTimeInMillis(date);
    int day = calendar.get(Calendar.DAY_OF_WEEK);
    while (day != startOfWeek) {
        calendar.add(Calendar.DATE, increment);
        day = calendar.get(Calendar.DAY_OF_WEEK);
    return startOfDayInMillis(calendar.getTimeInMillis());
StringgetDayNextWeek()
get Day Next Week
Calendar cal = new GregorianCalendar();
cal.roll(Calendar.DAY_OF_YEAR, +7);
return String.valueOf(cal.get(Calendar.DAY_OF_MONTH));
intgetDayOfTheWeekFromNow(int nDays)
Returns the day of week, 'nDays' from today
GregorianCalendar cal = new GregorianCalendar();
cal.add(Calendar.DAY_OF_YEAR, nDays);
return cal.get(Calendar.DAY_OF_WEEK);
intgetDayOfWeek()
get Day Of Week
Calendar date = Calendar.getInstance(Locale.US);
return date.get(Calendar.DAY_OF_WEEK);