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:Util.java

public static Date getLastMonthLastDate() {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.MONTH, -1);

    int max = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    calendar.set(Calendar.DAY_OF_MONTH, max);

    return calendar.getTime();
}

From source file:Main.java

public static Calendar GetLastYearRightRange(Calendar today) {
    Calendar calendar = (Calendar) today.clone();
    calendar.set(Calendar.MONTH, 0);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.add(Calendar.MINUTE, 0);
    return calendar;
}

From source file:Main.java

public static int getDayOfDate(Date date) {
    calendar.setTime(date);
    return calendar.get(Calendar.DAY_OF_MONTH) + 1;
}

From source file:Main.java

public static int getDay() {
    long ts = System.currentTimeMillis();
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(ts);/*w  w w .j  av  a 2 s  . c o  m*/
    return calendar.get(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static Date getPreNDay(Date presentDate, int n) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(presentDate);/*w  w w  . j  a v a2  s.  co  m*/
    calendar.add(Calendar.DAY_OF_MONTH, -n);
    presentDate = calendar.getTime();
    return presentDate;
}

From source file:Main.java

public static String getTodaysDate() {
    Calendar c = Calendar.getInstance();
    return c.get(Calendar.YEAR) + "-0" + String.valueOf(c.get(Calendar.MONTH) + 1) + "-"
            + c.get(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static long getCountDownDays(int dayMonth, int month, int year) {

    Calendar thatDay = Calendar.getInstance();
    thatDay.set(Calendar.DAY_OF_MONTH, dayMonth);
    thatDay.set(Calendar.MONTH, month - 1); // 0-11 so 1 less
    thatDay.set(Calendar.YEAR, year);

    Calendar today = Calendar.getInstance();
    long diff = thatDay.getTimeInMillis() - today.getTimeInMillis();

    return diff / (24 * 60 * 60 * 1000);

}

From source file:Main.java

public static String getCurrentTime() {
    Calendar c = Calendar.getInstance();
    int year = c.get(Calendar.YEAR);
    int month = c.get(Calendar.MONTH) + 1;
    int day = c.get(Calendar.DAY_OF_MONTH);
    String time = year + "-" + month + "-" + day;
    return time;/*from   w ww  .  j a  va  2  s.com*/
}

From source file:Main.java

private static long beginningOfTheDay(Calendar time) {
    Calendar copy = (Calendar) time.clone();
    copy.clear();/*from w  w  w  .ja v a 2  s  .c  om*/
    copy.set(time.get(Calendar.YEAR), time.get(Calendar.MONTH), time.get(Calendar.DAY_OF_MONTH));
    return copy.getTimeInMillis();
}

From source file:Main.java

public static Calendar todaysCalendar() {
    Calendar now = Calendar.getInstance();
    return createNewCalendar(now.get(Calendar.YEAR), now.get(Calendar.MONTH) + 1,
            now.get(Calendar.DAY_OF_MONTH));
}