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 String createCCPFileName() {
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(System.currentTimeMillis());

    int y = c.get(Calendar.YEAR);
    int m = c.get(Calendar.MONTH);
    int d = c.get(Calendar.DAY_OF_MONTH);
    int hour = c.get(Calendar.HOUR_OF_DAY);
    int minute = c.get(Calendar.MINUTE);
    int second = c.get(Calendar.SECOND);
    return y + "-" + m + "-" + d + "-" + hour + "-" + minute + "-" + second;
}

From source file:Main.java

public static int getWeekFromDay(int year, int month, int day) {
    Calendar calendar = Calendar.getInstance();
    calendar.clear();//from ww w.j  av  a  2 s . c o  m
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MONTH, month - 1);
    calendar.set(Calendar.DAY_OF_MONTH, day);
    return calendar.get(Calendar.WEEK_OF_YEAR);
}

From source file:Main.java

public static Date getNearestFutureDateWithHour(int hourOfDay) {
    Calendar cal = Calendar.getInstance();
    int hourOfDayNow = cal.get(Calendar.HOUR_OF_DAY);
    if (hourOfDayNow > hourOfDay) {
        cal.add(Calendar.DAY_OF_MONTH, 1);
    }//from  www.  j a  v a2 s.c  o  m

    cal.set(Calendar.HOUR, hourOfDay);
    return cal.getTime();
}

From source file:Main.java

public static int[] getWeekSunday(int year, int month, int day, int pervious) {
    int[] time = new int[3];
    Calendar c = Calendar.getInstance();
    c.set(Calendar.YEAR, year);/*from  w ww  . jav a2 s .  co  m*/
    c.set(Calendar.MONTH, month);
    c.set(Calendar.DAY_OF_MONTH, day);
    c.add(Calendar.DAY_OF_MONTH, pervious);
    time[0] = c.get(Calendar.YEAR);
    time[1] = c.get(Calendar.MONTH) + 1;
    time[2] = c.get(Calendar.DAY_OF_MONTH);
    return time;

}

From source file:Main.java

public static String get_date() {
    int mYear;/* w w w .ja  v  a2s.  co m*/
    int mMonth;
    int mDay;

    final Calendar c = Calendar.getInstance();

    mYear = c.get(Calendar.YEAR);
    mMonth = c.get(Calendar.MONTH) + 1;
    mDay = c.get(Calendar.DAY_OF_MONTH);

    String result = String.format("%04d-%02d-%02d", mYear, mMonth, mDay);
    return result;
}

From source file:Main.java

public static int getDayFromDate(Date date) {
    helperCalendar.setTime(date);
    return helperCalendar.get(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static java.util.Date getDateStart(java.util.Date d) {

    Calendar c = new GregorianCalendar();
    c.clear();// w w w . j a v  a 2s.  c  om
    Calendar co = new GregorianCalendar();
    co.setTime(d);
    c.set(Calendar.DAY_OF_MONTH, co.get(Calendar.DAY_OF_MONTH));
    c.set(Calendar.MONTH, co.get(Calendar.MONTH));
    c.set(Calendar.YEAR, co.get(Calendar.YEAR));
    // c.add(Calendar.DAY_OF_MONTH,1);
    // c.add(Calendar.MILLISECOND,-1);
    return c.getTime();
}

From source file:Main.java

public static boolean isInSameDay(Calendar calendar1, Calendar calendar2) {
    return calendar1.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR)
            && calendar1.get(Calendar.MONTH) == calendar2.get(Calendar.MONTH)
            && calendar1.get(Calendar.DAY_OF_MONTH) == calendar2.get(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static long getEndOfMonthMs(int year, int month) {
    final Calendar date = Calendar.getInstance();

    date.set(Calendar.YEAR, year);
    date.set(Calendar.MONTH, month);
    date.set(Calendar.DAY_OF_MONTH, date.getActualMaximum(Calendar.DAY_OF_MONTH));
    date.set(Calendar.HOUR_OF_DAY, date.getActualMaximum(Calendar.HOUR_OF_DAY));
    date.set(Calendar.MINUTE, date.getActualMaximum(Calendar.MINUTE));
    date.set(Calendar.SECOND, date.getActualMaximum(Calendar.SECOND));
    date.set(Calendar.MILLISECOND, date.getActualMaximum(Calendar.MILLISECOND));
    return date.getTimeInMillis();
}

From source file:Main.java

public static int getDays(int year, int month) {
    Calendar calendar = Calendar.getInstance();
    calendar.clear();// w  ww  .j  a va 2s.  c  o m
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MONTH, month - 1);
    int days = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    return days;
}