Example usage for java.util Calendar SUNDAY

List of usage examples for java.util Calendar SUNDAY

Introduction

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

Prototype

int SUNDAY

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

Click Source Link

Document

Value of the #DAY_OF_WEEK field indicating Sunday.

Usage

From source file:Main.java

public static String[] getShortWeekDays() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    String[] weekDays = new String[7];
    for (int i = 0; i < 7; i++) {
        weekDays[i] = SHORT_WEEK_DAYS_FORMAT.format(calendar.getTime());
        calendar.add(Calendar.DATE, 1);
    }//from  www  .ja  v a 2s  . co m
    return weekDays;
}

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

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;//from   www  .  java2  s. c  om

    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

private static boolean isWeekend(Calendar calendar) {
    int dayOfTheWeek = calendar.get(Calendar.DAY_OF_WEEK);
    return dayOfTheWeek == Calendar.SATURDAY || dayOfTheWeek == Calendar.SUNDAY;
}

From source file:Main.java

public static int getDayOfWeek(Date date, int defSunday) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);/*from  w w  w .j a  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

/**
 * //  w  ww . ja va  2  s  .co m
 * @return
 */
public static String ID_DayName() {
    Calendar cal = Calendar.getInstance();
    int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
    String weekDayName = "";

    if (Calendar.MONDAY == dayOfWeek) {
        weekDayName = "Senin";
    } else if (Calendar.TUESDAY == dayOfWeek) {
        weekDayName = "Selasa";
    } else if (Calendar.WEDNESDAY == dayOfWeek) {
        weekDayName = "Rabu";
    } else if (Calendar.THURSDAY == dayOfWeek) {
        weekDayName = "Kamis";
    } else if (Calendar.FRIDAY == dayOfWeek) {
        weekDayName = "Jumat";
    } else if (Calendar.SATURDAY == dayOfWeek) {
        weekDayName = "Sabtu";
    } else if (Calendar.SUNDAY == dayOfWeek) {
        weekDayName = "Minggu";
    }

    return weekDayName;
}

From source file:Main.java

private static String getDayOfWeek(String format, int calendarField) {
    String strDate = null;//from w w  w . j a  va  2s. co m
    try {
        Calendar c = new GregorianCalendar();
        SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format, Locale.CHINA);
        int week = c.get(Calendar.DAY_OF_WEEK);
        if (week == calendarField) {
            strDate = mSimpleDateFormat.format(c.getTime());
        } else {
            int offectDay = calendarField - week;
            if (calendarField == Calendar.SUNDAY) {
                offectDay = 7 - Math.abs(offectDay);
            }
            c.add(Calendar.DATE, offectDay);
            strDate = mSimpleDateFormat.format(c.getTime());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return strDate;
}

From source file:Main.java

public static boolean isWeekendDayInCalendar(Calendar calendar) {
    return calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY
            || calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY;
}

From source file:Main.java

private static String getDayOfWeek(String format, int calendarField) {
    String strDate = null;//from   w  ww . ja v  a2  s  . co m
    try {
        Calendar c = new GregorianCalendar();
        SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
        int week = c.get(Calendar.DAY_OF_WEEK);
        if (week == calendarField) {
            strDate = mSimpleDateFormat.format(c.getTime());
        } else {
            int offectDay = calendarField - week;
            if (calendarField == Calendar.SUNDAY) {
                offectDay = 7 - Math.abs(offectDay);
            }
            c.add(Calendar.DATE, offectDay);
            strDate = mSimpleDateFormat.format(c.getTime());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return strDate;
}

From source file:Main.java

/**
 * Converts the day of the week from android.text.format.Time to java.util.Calendar
 *///from   w ww . j  ava 2 s .c o  m
public static int convertDayOfWeekFromTimeToCalendar(int timeDayOfWeek) {
    switch (timeDayOfWeek) {
    case Time.MONDAY:
        return Calendar.MONDAY;
    case Time.TUESDAY:
        return Calendar.TUESDAY;
    case Time.WEDNESDAY:
        return Calendar.WEDNESDAY;
    case Time.THURSDAY:
        return Calendar.THURSDAY;
    case Time.FRIDAY:
        return Calendar.FRIDAY;
    case Time.SATURDAY:
        return Calendar.SATURDAY;
    case Time.SUNDAY:
        return Calendar.SUNDAY;
    default:
        throw new IllegalArgumentException("Argument must be between Time.SUNDAY and " + "Time.SATURDAY");
    }
}