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 void trunkMonth(Calendar c) {
    trunkDay(c);
    c.set(Calendar.DAY_OF_MONTH, 1);
}

From source file:Main.java

/**
 * Check the given date is February 29th.
 * @param calendar Calendar object to check
 * @return true if date is February 29th, else false.
 *///from   w  w w  . j  av  a  2s.co m
public static boolean isInsaneDate(Calendar calendar) {
    return calendar.get(Calendar.DAY_OF_MONTH) == 29 && calendar.get(Calendar.MONTH) == 1;
}

From source file:Main.java

/**
 * @param date/*from  ww w  .  j av a  2  s . co  m*/
 * @return
 */
private static String getDayFromDate(Date date) {
    if (date == null) {
        return null;
    }
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    return String.valueOf(cal.get(Calendar.DAY_OF_MONTH));
}

From source file:Main.java

/**
 * Get last month end day/*from   w  ww .  j a  va 2  s.com*/
 */
public static int getLastMonthEndDay() {
    Calendar lastDate = Calendar.getInstance();
    lastDate.add(Calendar.MONTH, -1);
    lastDate.set(Calendar.DATE, 1);
    lastDate.roll(Calendar.DATE, -1);
    return lastDate.getActualMaximum(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static double getJulDate() {
    Calendar cal = Calendar.getInstance();
    int year = cal.get(Calendar.YEAR);
    int month = cal.get(Calendar.MONTH) + 1;
    int day = cal.get(Calendar.DAY_OF_MONTH);
    int hour = cal.get(Calendar.HOUR_OF_DAY);
    int minute = cal.get(Calendar.MINUTE);
    int second = cal.get(Calendar.SECOND);
    double extra = (100.0 * year) + month - 190002.5;
    double julianDay = (367.0 * year) - (Math.floor(7.0 * (year + Math.floor((month + 9.0) / 12.0)) / 4.0))
            + Math.floor((275.0 * month) / 9.0) + day + ((hour + ((minute + (second / 60.0)) / 60.0)) / 24.0)
            + 1721013.5 - ((0.5 * extra) / Math.abs(extra)) + 0.5;
    DecimalFormat sixDigitFormat = new DecimalFormat("#.######");
    return Double.valueOf(sixDigitFormat.format(julianDay));
}

From source file:Main.java

public static Date getNextDay(Date date) {
    Calendar day = Calendar.getInstance();
    day.setTime(date);/*from  ww w. j a v  a  2  s  .  c om*/
    day.add(Calendar.DAY_OF_MONTH, 1);

    return day.getTime();
}

From source file:Main.java

/**
 * Get next month end day/*from   w w w  .j  av  a 2s.  c  o m*/
 *
 * @return
 */
public static int getNextMonthEndDay() {
    Calendar lastDate = Calendar.getInstance();
    lastDate.add(Calendar.MONTH, 1);
    lastDate.set(Calendar.DATE, 1);
    lastDate.roll(Calendar.DATE, -1);
    return lastDate.getActualMaximum(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static Bundle bundleCalendar(Calendar cal, long minDate) {
    Bundle args = new Bundle();
    if (cal == null)
        cal = Calendar.getInstance(Locale.getDefault());
    ;/* ww  w  .  ja v  a2s. c  o m*/
    args.putInt("year", cal.get(Calendar.YEAR));
    args.putInt("month", cal.get(Calendar.MONTH));
    args.putInt("day", cal.get(Calendar.DAY_OF_MONTH));
    args.putInt("hour", cal.get(Calendar.HOUR_OF_DAY));
    args.putInt("minute", cal.get(Calendar.MINUTE));
    args.putLong("minDate", minDate);
    return args;
}

From source file:Main.java

/**
 * Checks the calendar is today.//from  w ww .  jav a 2  s . c  o m
 * @param calendar Calendar object to check.
 * @return true if calendar is today else false.
 */
public static boolean isToday(Calendar calendar) {
    return calendar.get(Calendar.MONTH) == Calendar.getInstance().get(Calendar.MONTH)
            && calendar.get(Calendar.DAY_OF_MONTH) == Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

/**
 * Checks the calendar is tomorrow.//from   w w  w .  j  ava2s .c  o  m
 * @param calendar Calendar object to check.
 * @return true if calendar is tomorrow else false.
 */
public static boolean isTomorrow(Calendar calendar) {
    return calendar.get(Calendar.MONTH) == Calendar.getInstance().get(Calendar.MONTH)
            && calendar.get(Calendar.DAY_OF_MONTH) == (Calendar.getInstance().get(Calendar.DAY_OF_MONTH) + 1);
}