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

@SuppressLint("SimpleDateFormat")
public static String getCurrentTime() {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
    String time = formatter.format(new Date());
    Calendar c = Calendar.getInstance();
    int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);
    if (dayOfWeek == 1)
        time += ("07");
    else//from   w  w w  .  j  a va 2  s  . c  o m
        time += ("0" + (dayOfWeek - 1));
    return time;
}

From source file:Main.java

public static Integer GetDayOfWeekNumber(Date d) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(d);//  w ww. ja v a 2  s. com
    return cal.get(Calendar.DAY_OF_WEEK);
}

From source file:Main.java

public static int getDayWeek(int index) {
    int year = MIN_YEAR + index / 12;
    int month = index % 12;
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    Calendar date = new GregorianCalendar(year, month, 1);
    int dayweek = date.get(Calendar.DAY_OF_WEEK);
    return dayweek;

}

From source file:Main.java

public static long timeInMillis(int hour, int minute) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.MINUTE, minute);
    calendar.set(Calendar.SECOND, 0);

    long timeBefore = calendar.getTimeInMillis();

    if (Calendar.getInstance().getTimeInMillis() > timeBefore)
        calendar.add(Calendar.DAY_OF_WEEK, 1);
    return calendar.getTimeInMillis();
}

From source file:Main.java

public static long getStartOfWeek(long week) {
    Calendar calendar = getCalendarWithTime(week);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.clear(Calendar.MINUTE);
    calendar.clear(Calendar.SECOND);
    calendar.clear(Calendar.MILLISECOND);

    // get start of this week in milliseconds
    calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek());

    return calendar.getTimeInMillis();
}

From source file:Main.java

/**
 * Returns the previous day of the passed {@link Date}
 *
 * @return The date - 24 hours/*  w w  w. j  ava2 s  .c  om*/
 */
public static Date getYesterday(Date date) {
    if (date == null) {
        return getYesterday(new Date());
    }

    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.add(Calendar.DAY_OF_WEEK, -1);

    return new Date(cal.getTimeInMillis());
}

From source file:Main.java

/**
 * the first day of month/*w  ww  .j a v a  2  s.co m*/
 * @param year
 * @param month
 * @return week position
 */
public static int getDayOfWeekInMonth(int year, int month) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MONTH, month - 1);
    calendar.set(Calendar.DATE, 1);
    return calendar.get(Calendar.DAY_OF_WEEK);
}

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 String getAbbrevDayOfWeekString(Calendar date) {
    return getAbbrevDayOfWeekString(date.get(Calendar.DAY_OF_WEEK));
}

From source file:Main.java

public static Calendar calculateNextAlarmTime(int repetition) {
    if (repetition == 0)
        return null;
    Calendar alarmTime = Calendar.getInstance();
    alarmTime.set(Calendar.HOUR_OF_DAY, 20);
    alarmTime.set(Calendar.MINUTE, 0);
    alarmTime.set(Calendar.SECOND, 0);

    int day_of_week = alarmTime.get(Calendar.DAY_OF_WEEK) - 2;
    if (day_of_week == -1)
        day_of_week = 6;// sunday
    repetition &= 0x7f;//  w w  w.jav  a 2  s  .c  o  m
    int rot = (repetition >> (day_of_week + 1)) | (repetition << (7 - day_of_week - 1));
    rot &= 0x7f;
    int ndays = 0;
    for (ndays = 0; ndays < 7; ndays++) {
        if ((rot & (1 << ndays)) != 0)
            break;
    }
    alarmTime.add(Calendar.DATE, ndays + 1);

    return alarmTime;
}