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 boolean CoversFYStart(Calendar one, Calendar two, Calendar fy_start) throws Exception {
    if (one == null || two == null)
        throw new Exception("CoversFYStart: Null dates passed in");
    if (fy_start == null)
        throw new Exception("CoversFYStart: Null FY Start");

    int fy_month = fy_start.get(Calendar.MONTH);
    int fy_day = fy_start.get(Calendar.DAY_OF_MONTH);
    Calendar cal = (Calendar) one.clone();

    while (true) {
        cal.add(Calendar.DATE, 1);
        int month = cal.get(Calendar.MONTH);
        int day = cal.get(Calendar.DAY_OF_MONTH);
        if (month == fy_month && day == fy_day)
            break;
    }/*from  ww  w .  j av a 2  s  . co m*/

    return cal.before(two);
}

From source file:Main.java

public static String getDateString() {
    String stringDate = "";
    Calendar calendar = Calendar.getInstance();
    int day = calendar.get(Calendar.DAY_OF_WEEK);
    int month = calendar.get(Calendar.MONTH);
    int dayInt = calendar.get(Calendar.DAY_OF_MONTH);
    switch (day) {
    case Calendar.SUNDAY:
        stringDate += "Sunday";
        break;//from  w w  w. ja  va  2s . c om

    case Calendar.MONDAY:
        stringDate += "Monday";
        break;

    case Calendar.TUESDAY:
        stringDate += "Tuesday";
        break;

    case Calendar.WEDNESDAY:
        stringDate += "Wednesday";
        break;

    case Calendar.THURSDAY:
        stringDate += "Thursday";
        break;

    case Calendar.FRIDAY:
        stringDate += "Friday";
        break;

    case Calendar.SATURDAY:
        stringDate += "Saturday";
        break;

    }
    switch (month) {
    case Calendar.JANUARY:
        stringDate += ", January";
        break;

    case Calendar.FEBRUARY:
        stringDate += ", February";
        break;

    case Calendar.MARCH:
        stringDate += ", March";
        break;

    case Calendar.APRIL:
        stringDate += ", April";
        break;

    case Calendar.MAY:
        stringDate += ", May";
        break;

    case Calendar.JUNE:
        stringDate += ", June";
        break;

    case Calendar.JULY:
        stringDate += ", July";
        break;

    case Calendar.AUGUST:
        stringDate += ", August";
        break;

    case Calendar.SEPTEMBER:
        stringDate += ", September";
        break;

    case Calendar.OCTOBER:
        stringDate += ", October";
        break;

    case Calendar.NOVEMBER:
        stringDate += ", November";
        break;

    case Calendar.DECEMBER:
        stringDate += ", December";
        break;

    }

    stringDate += (" " + dayInt);

    return stringDate;
}

From source file:Main.java

public static String getTimeStamp(long l) {
    Calendar cal = new GregorianCalendar();
    cal.setTimeInMillis(l);/*from w  w w . j av  a2 s .  co m*/
    return makeTimeString(cal.get(Calendar.DAY_OF_MONTH), 2) + "."
            + makeTimeString(cal.get(Calendar.MONTH) + 1, 2) + "." + makeTimeString(cal.get(Calendar.YEAR), 4)
            + " " + makeTimeString(cal.get(Calendar.HOUR_OF_DAY), 2) + ":"
            + makeTimeString(cal.get(Calendar.MINUTE), 2) + ":" + makeTimeString(cal.get(Calendar.SECOND), 2);
}

From source file:Main.java

public static String getTimeStampDDMMYYYY(long l) {
    Calendar cal = new GregorianCalendar();
    cal.setTimeInMillis(l);//from ww  w  .  j  a v a 2s  .  c o  m
    return makeTimeString(cal.get(Calendar.DAY_OF_MONTH), 2) + "."
            + makeTimeString(cal.get(Calendar.MONTH) + 1, 2) + "." + makeTimeString(cal.get(Calendar.YEAR), 4);
}

From source file:Main.java

public static boolean checkToday(String date) {
    Calendar today = Calendar.getInstance();
    Calendar day = StringToCalendar(date);
    return ((today.get(Calendar.YEAR) == day.get(Calendar.YEAR))
            && (today.get(Calendar.MONTH) == day.get(Calendar.MONTH))
            && (today.get(Calendar.DAY_OF_MONTH) == day.get(Calendar.DAY_OF_MONTH)));
}

From source file:Main.java

public static Bundle bundleCalendar(Calendar cal) {
    Bundle args = new Bundle();
    if (cal == null)
        cal = Calendar.getInstance(Locale.getDefault());
    ;//from  w  w  w . j  a  v  a 2s  .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));
    return args;
}

From source file:Main.java

public static List<Integer> getAllDayInMonth(int month, int year) {
    List<Integer> listDate = new ArrayList<Integer>();

    Calendar calendar = Calendar.getInstance();
    calendar.set(year, month, 1);// w w  w  . j a v  a 2s  .  co  m
    calendar.clear(Calendar.HOUR);
    calendar.clear(Calendar.MINUTE);
    calendar.clear(Calendar.SECOND);
    int totalDays = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);

    for (int i = 1; i <= totalDays; i++) {
        listDate.add(i);
    }
    return listDate;
}

From source file:Main.java

private static long countDays(Calendar start, Calendar end) {
    long totalNumberOfDays = 0;
    while (start.before(end)) {
        start.add(Calendar.DAY_OF_MONTH, 1);
        totalNumberOfDays++;//from w w w  .  j  ava  2s.  c om
    }
    return totalNumberOfDays;
}

From source file:Main.java

/**
 * Is a dateTime today//from   www .ja va 2s .  com
 * @param dateTimeString in format 2012-10-15T08:17:00
 * @return true if today
 * */
public static boolean isToday(String depDateTime) {
    boolean isToday = false;
    Calendar depDate = parseCalendarString(depDateTime);
    int depDay = depDate.get(Calendar.DAY_OF_MONTH);
    Calendar now = getTimeNow();
    int nowDay = now.get(Calendar.DAY_OF_MONTH);
    if (depDay == nowDay) {
        isToday = true;
    }
    return isToday;
}

From source file:Main.java

public static XMLGregorianCalendar convertDate(Date date) {
    try {//  w  w w .ja va 2  s.com
        Calendar c = new GregorianCalendar();
        c.setTime(date);
        XMLGregorianCalendar xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar();
        xmlGregorianCalendar.setDay(c.get(Calendar.DAY_OF_MONTH));
        xmlGregorianCalendar.setMonth(c.get(Calendar.MONTH));
        xmlGregorianCalendar.setYear(c.get(Calendar.YEAR));
        return xmlGregorianCalendar;
    } catch (DatatypeConfigurationException e) {
        throw new RuntimeException(e);
    }
}