Example usage for java.util Calendar DAY_OF_WEEK

List of usage examples for java.util Calendar DAY_OF_WEEK

Introduction

In this page you can find the example usage for java.util Calendar DAY_OF_WEEK.

Prototype

int DAY_OF_WEEK

To view the source code for java.util Calendar DAY_OF_WEEK.

Click Source Link

Document

Field number for get and set indicating the day of the week.

Usage

From source file:Main.java

private static Date getNextBus(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/*from  w w w . j a  va2s. com*/

    if (cal.get(Calendar.DAY_OF_WEEK) >= Calendar.MONDAY
            && cal.get(Calendar.DAY_OF_WEEK) <= Calendar.THURSDAY) {
        if (isBefore(cal, mon_thu[mon_thu.length - 1])) {
            setTime(cal, findNext(cal, mon_thu));
        } else if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.THURSDAY) {
            setTime(cal, fri[0]);
            cal.add(Calendar.DAY_OF_YEAR, 1);
        } else {
            setTime(cal, mon_thu[0]);
            cal.add(Calendar.DAY_OF_YEAR, 1);
        }
    } else if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY) {
        if (isBefore(cal, fri[fri.length - 1])) {
            setTime(cal, findNext(cal, fri));
        } else {
            setTime(cal, mon_thu[0]);
            cal.add(Calendar.DAY_OF_YEAR, 3);
        }
    } else {
        setTime(cal, mon_thu[0]);
        cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
    }
    return cal.getTime();
}

From source file:Main.java

public static int dayForWeek(String pTime) throws Exception {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    Calendar c = Calendar.getInstance();
    c.setTime(format.parse(pTime));/*  w  w  w . j  a v a  2  s  .  co m*/
    int dayForWeek = 0;

    return c.get(Calendar.DAY_OF_WEEK);
}

From source file:Main.java

private static Date weekDay(int week) {
    Calendar cal = calendar();
    cal.set(Calendar.DAY_OF_WEEK, week);
    return cal.getTime();
}

From source file:Main.java

public static String getDateString() {
    String stringDate = "";
    Calendar calendar = Calendar.getInstance();
    int day = calendar.get(Calendar.DAY_OF_WEEK);
    int month = calendar.get(Calendar.MONTH);
    int dayInt = calendar.get(Calendar.DAY_OF_MONTH);
    switch (day) {
    case Calendar.SUNDAY:
        stringDate += "Sunday";
        break;/*w w w . j  a  v a2 s. c  o  m*/

    case Calendar.MONDAY:
        stringDate += "Monday";
        break;

    case Calendar.TUESDAY:
        stringDate += "Tuesday";
        break;

    case Calendar.WEDNESDAY:
        stringDate += "Wednesday";
        break;

    case Calendar.THURSDAY:
        stringDate += "Thursday";
        break;

    case Calendar.FRIDAY:
        stringDate += "Friday";
        break;

    case Calendar.SATURDAY:
        stringDate += "Saturday";
        break;

    }
    switch (month) {
    case Calendar.JANUARY:
        stringDate += ", January";
        break;

    case Calendar.FEBRUARY:
        stringDate += ", February";
        break;

    case Calendar.MARCH:
        stringDate += ", March";
        break;

    case Calendar.APRIL:
        stringDate += ", April";
        break;

    case Calendar.MAY:
        stringDate += ", May";
        break;

    case Calendar.JUNE:
        stringDate += ", June";
        break;

    case Calendar.JULY:
        stringDate += ", July";
        break;

    case Calendar.AUGUST:
        stringDate += ", August";
        break;

    case Calendar.SEPTEMBER:
        stringDate += ", September";
        break;

    case Calendar.OCTOBER:
        stringDate += ", October";
        break;

    case Calendar.NOVEMBER:
        stringDate += ", November";
        break;

    case Calendar.DECEMBER:
        stringDate += ", December";
        break;

    }

    stringDate += (" " + dayInt);

    return stringDate;
}

From source file:Main.java

public static List<String> getWeekDate() {
    List<String> list = new ArrayList<String>();
    Calendar calendar = Calendar.getInstance(Locale.CHINA);
    calendar.setTime(new Date());
    calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
    list.add(calendar.get(Calendar.MONTH) + 1 + "." + calendar.get(Calendar.DATE));
    for (int i = 0; i < 6; i++) {
        calendar.add(Calendar.DATE, 1);
        String str = calendar.get(Calendar.MONTH) + 1 + "." + calendar.get(Calendar.DATE);
        list.add(str);/* w ww .  j  a v  a  2  s.com*/
    }
    return list;
}

From source file:Main.java

public static Date firstTimeOfWeek(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(date.getTime());

    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);

    Date dateBegin = new Date();
    dateBegin.setTime(calendar.getTimeInMillis());
    return dateBegin;
}

From source file:Main.java

private static int getCurrentDay() {
    return Calendar.getInstance().get(Calendar.DAY_OF_WEEK);
}

From source file:Main.java

public static int getDayOfWeek(Date date, int defSunday) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);//from ww w .ja v a 2  s  .c  o m
    int day = c.get(Calendar.DAY_OF_WEEK);
    switch (day) {
    case Calendar.MONDAY:
        return 1;
    case Calendar.TUESDAY:
        return 2;
    case Calendar.WEDNESDAY:
        return 3;
    case Calendar.THURSDAY:
        return 4;
    case Calendar.FRIDAY:
        return 5;
    case Calendar.SATURDAY:
        return 6;
    case Calendar.SUNDAY:
        return defSunday;
    default:
        return 0;
    }
}

From source file:Main.java

public static ArrayList<String> getCurrentWeek() {
    SimpleDateFormat format = new SimpleDateFormat("dd");
    Calendar calendar = Calendar.getInstance();
    calendar.setFirstDayOfWeek(Calendar.SUNDAY);
    calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);

    ArrayList<String> days = new ArrayList<String>();
    for (int i = 0; i < 7; i++) {
        days.add(format.format(calendar.getTime()));
        calendar.add(Calendar.DAY_OF_MONTH, 1);
    }/*from www  .j a  v a 2s . co m*/
    return days;
}

From source file:Main.java

public static String weekDay(String year, String month, String day) {
    String strWeekday = "";
    try {//w  w  w .j a  v a 2  s .c o  m
        GregorianCalendar cal = new GregorianCalendar();
        cal.setLenient(false);
        cal.clear();
        cal.set(Integer.parseInt(year), Integer.parseInt(month) - 1, Integer.parseInt(day));
        strWeekday = String.valueOf(cal.get(Calendar.DAY_OF_WEEK) - 1);
    } catch (IllegalArgumentException e) {
        strWeekday = "";
    }
    return strWeekday;
}