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 void prepareCalendarStartsMonday(Calendar calendar) {
    if (calendar.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
        if (dayOfWeek == Calendar.SUNDAY) {
            calendar.add(Calendar.DATE, -6);
        } else {//from  w  w w.  j av  a2 s . co m
            calendar.add(Calendar.DATE, -dayOfWeek + 2);
        }
    }
}

From source file:Main.java

public static String getWeekDay(int position) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.DAY_OF_WEEK, position + 1);

    return calendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, Locale.getDefault());
}

From source file:Main.java

public static int getWeekdayOfMonth(Calendar c) {
    Calendar cal = (Calendar) c.clone();
    cal.set(Calendar.DATE, 1);//  w  w w .j a  v  a 2  s . c o  m
    return cal.get(Calendar.DAY_OF_WEEK) - 1;
}

From source file:Main.java

public static boolean isFridayOrSaturday() {
    Calendar date = new GregorianCalendar();
    return date.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY
            || date.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY;
}

From source file:Main.java

public static Calendar nextMonday() {
    Calendar date = new GregorianCalendar();
    while (date.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
        date.add(Calendar.DATE, 1);
    }/*from  w w w.ja v a 2  s  . c  o  m*/
    date.set(Calendar.HOUR_OF_DAY, 0);
    date.set(Calendar.MINUTE, 0);
    date.set(Calendar.SECOND, 0);
    date.set(Calendar.MILLISECOND, 0);
    return date;
}

From source file:Main.java

public static int getWeekOfDate(Date dt) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(dt);//from   w w w. ja  v  a2  s  . c  o m
    int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
    return w < 0 ? 0 : w;
}

From source file:Main.java

public static int getDayOfTheWeek() {
    Calendar calendar = Calendar.getInstance();
    int day = calendar.get(Calendar.DAY_OF_WEEK);

    return day;/*  w w  w .j  a va  2s  .  c  o  m*/
}

From source file:Main.java

public static int dayOfWeek() {
    return calendar().get(Calendar.DAY_OF_WEEK);
}

From source file:Main.java

public static int getWeekday(long time) {
    Calendar min = Calendar.getInstance();
    min.setTimeInMillis(time);// w ww.j  av  a  2s.  c o m
    return min.get(Calendar.DAY_OF_WEEK);
}

From source file:Main.java

public static boolean IsItTheWeekend() {
    Calendar calendarToday = Calendar.getInstance();

    if (calendarToday.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY
            || calendarToday.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
        //TODO: //Change back to true, set to false to test information on the weekend
        return true;
    } else {//from   w w w .j a  va2  s .  com
        return false;
    }

}