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 Date addDays(Date date, Integer days) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);//from w ww.  ja va2 s. c om
    cal.add(Calendar.DAY_OF_MONTH, days);
    return cal.getTime();
}

From source file:Main.java

public static int getFirstDayOfWeek(Date date) {
    int n = getDayOfWeek(date);
    Calendar c = Calendar.getInstance();
    c.setTime(date);/*from  w w w. java2  s .  com*/
    c.set(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH) - n + 1);
    return c.get(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static long getTimesMonthMorning() {
    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 Date lastTimeOfMonth(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/*from ww w. j  a  va  2 s. c o m*/
    cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
    cal.set(Calendar.HOUR_OF_DAY, cal.getActualMaximum(Calendar.HOUR_OF_DAY));
    cal.set(Calendar.MINUTE, cal.getActualMaximum(Calendar.MINUTE));
    cal.set(Calendar.SECOND, cal.getActualMaximum(Calendar.SECOND));
    cal.set(Calendar.MILLISECOND, cal.getActualMaximum(Calendar.MILLISECOND));
    return cal.getTime();
}

From source file:Main.java

public static int getDay(Date date) {
    calendar = Calendar.getInstance();
    calendar.setTime(date);/*  w w w  . j a va2 s.  c  o  m*/
    return calendar.get(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static Date firstTimeOfMonth(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);//from   ww  w .  j a v a  2  s.c om
    cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
    cal.set(Calendar.HOUR_OF_DAY, cal.getActualMinimum(Calendar.HOUR_OF_DAY));
    cal.set(Calendar.MINUTE, cal.getActualMinimum(Calendar.MINUTE));
    cal.set(Calendar.SECOND, cal.getActualMinimum(Calendar.SECOND));
    cal.set(Calendar.MILLISECOND, cal.getActualMinimum(Calendar.MILLISECOND));
    return cal.getTime();
}

From source file:Main.java

public static String getNow() {
    final Calendar calendar = Calendar.getInstance();
    return calendar.get(Calendar.YEAR) + "/" + calendar.get(Calendar.MONTH) + 1 + "/"
            + calendar.get(Calendar.DAY_OF_MONTH) + "/" + " " + calendar.get(Calendar.HOUR_OF_DAY) + ":"
            + calendar.get(Calendar.MINUTE) + ":" + calendar.get(Calendar.SECOND);
}

From source file:Main.java

public static int getYesterdayDay() {
    long ts = System.currentTimeMillis() - 24 * 3600000;
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(ts);/*from  ww w  .  j a  va  2  s  .c o m*/
    return calendar.get(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static long getYesterTime() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    calendar.add(Calendar.DAY_OF_MONTH, -1);
    return calendar.getTimeInMillis();
}

From source file:Main.java

public static void copyTo(Calendar from, Calendar to) {
    int year = from.get(Calendar.YEAR);
    int month = from.get(Calendar.MONTH);
    int day = from.get(Calendar.DAY_OF_MONTH);
    to.set(year, month, day);//from  w  ww  . j a  va2 s.c om
    to.getTimeInMillis();
}