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 getNextMonthDays(Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);// w w w .j  a v a  2 s .  c o  m
    c.add(Calendar.MONTH, 1);
    return c.getActualMaximum(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static String formatCalendar(Calendar calendar) {
    if (calendar != null) {
        return calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-"
                + calendar.get(Calendar.DAY_OF_MONTH);
    } else {//from   w ww .j a v a 2 s  . co  m
        return null;
    }
}

From source file:Main.java

public static Date rewindToBeginningOfMonth(Date date) {
    Calendar cal = buildFromDate(rewindToBeginningOfDay(date));
    cal.set(Calendar.DAY_OF_MONTH, 1);
    return cal.getTime();
}

From source file:Main.java

public static boolean isSameDay(Calendar cal1, Calendar cal2) {
    return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)
            && cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH)
            && cal1.get(Calendar.DAY_OF_MONTH) == cal2.get(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static final int getDayByMill(long mill) {
    Date curDate = new Date(mill);
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(curDate);/*from www  .j ava  2s.  c  om*/
    return calendar.get(java.util.Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static int getTheMonthDayCount(Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);//from   w  ww.  j  a va2s.  co m
    int lastDay = c.getActualMaximum(Calendar.DAY_OF_MONTH);

    return lastDay;
}

From source file:Main.java

public static int getDaysOfMonth(int year, int month) {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month - 1);
    int days = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
    return days;/*  w w  w .j a v a2  s  . c  om*/
}

From source file:Main.java

public static String getFirstDayOfLastMonth() {
    Calendar c = Calendar.getInstance();
    int month = c.get(Calendar.MONTH);
    c.set(Calendar.MONTH, month - 1);
    c.set(Calendar.DAY_OF_MONTH, c.getActualMinimum(Calendar.DAY_OF_MONTH));
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    return df.format(c.getTime());
}

From source file:Main.java

public static String getTodayDateString() {
    Calendar now = Calendar.getInstance();
    int year = now.get(Calendar.YEAR);
    int month = now.get(Calendar.MONTH) + 1;
    int day = now.get(Calendar.DAY_OF_MONTH);

    String monthStr = String.valueOf(month);
    String dayStr = String.valueOf(day);

    if (month < 10) {
        monthStr = "0" + dayStr;
    }/*from   ww  w  .  j  a v a 2s . c o m*/
    if (day < 10) {
        dayStr = "0" + dayStr;
    }

    String nowDate = year + "-" + monthStr + "-" + dayStr;
    return nowDate;
}

From source file:Main.java

public static String getNowDate(int afterDay) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DAY_OF_MONTH, afterDay);
    return dateFormat.format(calendar.getTime());
}