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

private static final Calendar getUtcDate(int year, int month, int dayOfMonth) {
    final Calendar calendar = Calendar.getInstance(UTC_TIMEZONE, Locale.US);
    calendar.clear();/*from   w ww .  j a  v  a  2s .  c  o m*/
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MONTH, month);
    calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
    return calendar;
}

From source file:com.github.jgility.core.util.ReleasePlanningUtils.java

private static Calendar addDayOffset(final Calendar date, long offset) {
    Calendar newDate = new GregorianCalendar();
    newDate.setTimeInMillis(date.getTimeInMillis());
    newDate.add(Calendar.DAY_OF_MONTH, safeLongToInt(offset));
    return newDate;
}

From source file:com.castis.xylophone.adsmadapter.common.util.CiDateUtil.java

public static int countDay(Calendar start, Calendar end, InventoryBoxDayCode dayCode) {

    int count = 0;

    while (start.compareTo(end) <= 0) {

        int day = start.get(Calendar.DAY_OF_WEEK);

        if (dayCode != null) {
            if (Calendar.MONDAY <= day && Calendar.FRIDAY >= day) {
                if (dayCode.equals(InventoryBoxDayCode.WEEKDAY))
                    count++;/* w  w  w . j  av a2  s .  c om*/
            } else {
                if (dayCode.equals(InventoryBoxDayCode.WEEKEND))
                    count++;
            }
        } else {
            count++;
        }

        start.add(Calendar.DAY_OF_MONTH, 1);
    }

    return count;
}

From source file:Main.java

public static int compareDates(java.util.Date startDate, java.util.Date endDate) {
    int interval = 0;

    calendarStartDate = Calendar.getInstance();
    calendarStartDate.set(Calendar.YEAR, startDate.getYear());
    calendarStartDate.set(Calendar.MONTH, startDate.getMonth());
    calendarStartDate.set(Calendar.DAY_OF_MONTH, startDate.getDate());

    calendarEndDate.set(Calendar.YEAR, endDate.getYear());
    calendarEndDate.set(Calendar.MONTH, endDate.getMonth());
    calendarEndDate.set(Calendar.DAY_OF_MONTH, endDate.getDate());

    long diff = calendarEndDate.getTimeInMillis() - calendarStartDate.getTimeInMillis();
    interval = (int) (diff / (24 * 60 * 60 * 1000) + 1); // plus one day

    return interval;
}

From source file:Main.java

/**
 * Compares only the month, day, and year of the provided calendars
 * @param date1 The calendar to compare against
 * @param date2 The calendar to compare/*from  w  w w  .j av a 2 s  .c o  m*/
 * @return -1 if the first calendar is earlier, 1 if the second calendar is earlier, 0 otherwise
 */
public static int compareDates(Calendar date1, Calendar date2) {
    if (date1.get(Calendar.YEAR) < date2.get(Calendar.YEAR)) {
        return -1;
    } else if (date1.get(Calendar.YEAR) > date2.get(Calendar.YEAR)) {
        return 1;
    }
    // Years are equal
    if (date1.get(Calendar.MONTH) < date2.get(Calendar.MONTH)) {
        return -1;
    } else if (date1.get(Calendar.MONTH) > date2.get(Calendar.MONTH)) {
        return 1;
    }
    // Years and months are equal
    if (date1.get(Calendar.DAY_OF_MONTH) < date2.get(Calendar.DAY_OF_MONTH)) {
        return -1;
    } else if (date1.get(Calendar.DAY_OF_MONTH) > date2.get(Calendar.DAY_OF_MONTH)) {
        return 1;
    }
    return 0;
}

From source file:DateUtils.java

public static String getDate() {
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());

    int year = cal.get(Calendar.YEAR);
    int month = cal.get(Calendar.MONTH) + 1;
    int day = cal.get(Calendar.DAY_OF_MONTH);

    return "" + year + "-" + month + "-" + day;
}

From source file:Main.java

public static Date getDateFromHexString(String hexString) {
    Calendar c = Calendar.getInstance();
    int year = Integer.parseInt(hexString.substring(0, 2)) + 2000;
    int month = Integer.parseInt(hexString.substring(2, 4));
    int day = Integer.parseInt(hexString.substring(4, 6));

    c.set(Calendar.YEAR, year);/*from  www.j a v  a2 s  . c o m*/
    c.set(Calendar.MONTH, month - 1);
    c.set(Calendar.DAY_OF_MONTH, day);

    return c.getTime();
}

From source file:DateUtils.java

/**
 * A method to get the current date as an array of components
 * 0 = year, 1 = month, 2 = day//  ww  w  .j a va 2  s  .c  o  m
 *
 * @return an array of strings representing the current date
 */
public static String[] getCurrentDateAsArray() {

    GregorianCalendar calendar = new GregorianCalendar();
    String[] fields = new String[3];

    fields[0] = Integer.toString(calendar.get(Calendar.YEAR));
    fields[1] = String.format("%02d", calendar.get(Calendar.MONTH) + 1);
    fields[2] = String.format("%02d", calendar.get(Calendar.DAY_OF_MONTH));

    return fields;
}

From source file:Dates.java

/**
 * Returns the day of date. <p>//from   w w w .  j ava2  s  .  co  m
 * 
 * If date is null return 0.
 */
public static int getDay(Date date) {
    if (date == null)
        return 0;
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    return cal.get(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static Calendar createCalendar(int dayOfMonth, int hour, int minute) {
    Calendar calendar = createCalendar(hour, minute);
    calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
    return calendar;
}