Example usage for java.util Calendar DAY_OF_MONTH

List of usage examples for java.util Calendar DAY_OF_MONTH

Introduction

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

Prototype

int DAY_OF_MONTH

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

Click Source Link

Document

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

Usage

From source file:Main.java

public static int getDayForWeekInMonth(int date, Calendar calendar) {
    if (date < 1 || date > 31) {
        return 1;
    }//from   ww  w.  ja  va  2  s  .  co  m
    calendar.set(Calendar.DAY_OF_MONTH, date);
    return calendar.get(Calendar.DAY_OF_WEEK) - 1;
}

From source file:Main.java

public static int getDayOfMonth() {
    Calendar c = Calendar.getInstance();
    c.setTime(new Date());
    int year = c.get(Calendar.DAY_OF_MONTH);
    return year;/*from   w  w w .  ja va  2s. c o m*/
}

From source file:Main.java

public static Integer GetDayOfMonth(Date d) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(d);
    return cal.get(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static long getTimesMonthStart() {
    Calendar cal = Calendar.getInstance();
    cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
    cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
    return cal.getTimeInMillis();
}

From source file:Main.java

public static Calendar getLastFriday(Calendar cal, int offset) {
    int dayofweek;
    cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) + offset);
    cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
    dayofweek = cal.get(Calendar.DAY_OF_WEEK);
    if (dayofweek < Calendar.FRIDAY)
        cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) - 7 + Calendar.FRIDAY - dayofweek);
    else// ww  w  .  j a va  2  s  . com
        cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) + Calendar.FRIDAY - dayofweek);

    return cal;
}

From source file:Main.java

public static Calendar nextDayOfWeek(int dow) {
    Calendar date = Calendar.getInstance();
    int diff = dow - date.get(Calendar.DAY_OF_WEEK);
    if (!(diff > 0)) {
        diff += 7;//from   w w w.  ja  va2  s  .c om
    }
    date.add(Calendar.DAY_OF_MONTH, diff);
    return date;
}

From source file:Main.java

public static Date lastDayOfMonth(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);//from w  w w  . ja v a  2  s. c o  m
    cal.set(Calendar.DAY_OF_MONTH, Calendar.getInstance().getActualMaximum(Calendar.DAY_OF_MONTH));
    cal.set(Calendar.HOUR_OF_DAY, Calendar.getInstance().getActualMaximum(Calendar.HOUR_OF_DAY));
    cal.set(Calendar.MINUTE, Calendar.getInstance().getActualMaximum(Calendar.MINUTE));
    return cal.getTime();
}

From source file:Main.java

public static Date firstDayOfMonth(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);//  w  w  w .ja  v a 2 s . com
    cal.set(Calendar.DAY_OF_MONTH, Calendar.getInstance().getActualMinimum(Calendar.DAY_OF_MONTH));
    cal.set(Calendar.HOUR_OF_DAY, Calendar.getInstance().getActualMinimum(Calendar.HOUR_OF_DAY));
    cal.set(Calendar.MINUTE, Calendar.getInstance().getActualMinimum(Calendar.MINUTE));
    return cal.getTime();
}

From source file:Main.java

public static long getTimesMonthNextStart() {
    Calendar cal = Calendar.getInstance();
    cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
    cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
    cal.set(Calendar.HOUR_OF_DAY, 24);
    return cal.getTimeInMillis();
}

From source file:Main.java

public static long getEndOfCurrentMonth() {
    Calendar calendar = getCurrentCalendar();
    calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
    return calendar.getTimeInMillis();
}