Example usage for java.util Calendar getActualMaximum

List of usage examples for java.util Calendar getActualMaximum

Introduction

In this page you can find the example usage for java.util Calendar getActualMaximum.

Prototype

public int getActualMaximum(int field) 

Source Link

Document

Returns the maximum value that the specified calendar field could have, given the time value of this Calendar.

Usage

From source file:Main.java

public static int getUpMonthDays(Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);/*  w  w  w  .j a v  a 2 s . c om*/
    c.add(Calendar.MONTH, -1);
    return c.getActualMaximum(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static java.util.Date getDate(int y, int m, int d, boolean inclusive) {
    java.util.Date dt = null;// ww  w .  j av  a2 s. c  o  m
    Calendar c = Calendar.getInstance();
    c.clear();
    if (c.getActualMinimum(1) <= y && y <= c.getActualMaximum(1)) {
        c.set(1, y);
        if (c.getActualMinimum(2) <= m && m <= c.getActualMaximum(2)) {
            c.set(2, m);
            if (c.getActualMinimum(5) <= d && d <= c.getActualMaximum(5))
                c.set(5, d);
        }
        if (inclusive) {
            c.add(5, 1);
            c.add(14, -1);
        }
        dt = c.getTime();
    }
    return dt;
}

From source file:Main.java

public static int getMonthDayNumber(int offset) {
    Calendar calendar = Calendar.getInstance();
    if (offset != 0)
        calendar.add(Calendar.MONTH, offset);
    return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static Calendar getLastFriday(Calendar cal, int offset) {
    int dayofweek;
    cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) + offset);
    cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
    dayofweek = cal.get(Calendar.DAY_OF_WEEK);
    if (dayofweek < Calendar.FRIDAY)
        cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) - 7 + Calendar.FRIDAY - dayofweek);
    else/*w w  w .j  a  va  2s.co m*/
        cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) + Calendar.FRIDAY - dayofweek);

    return cal;
}

From source file:Main.java

/**
 * set to the last day of month/*from   w  ww .ja va  2s  . c  om*/
 * @param calendar
 */
public static void setToLastDay(Calendar calendar) {
    int year = getYear(calendar);
    int month = getMonth(calendar);
    int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    calendar.clear();
    calendar.set(year, month, maxDay);
    calendar.getTimeInMillis();
}

From source file:Main.java

public static int getDaysOfMonth(int year, int month) {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month - 1);
    int days = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
    return days;/*ww  w .  j av a2s. c o m*/
}

From source file:Main.java

public static int getdataCount(int year, int month) {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month - 1);
    int count = cal.getActualMaximum(Calendar.DATE);
    return count;
}

From source file:Main.java

public static int getMonthOfDays(int year, int month) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MONTH, month);
    return calendar.getActualMaximum(Calendar.DATE);
}

From source file:Main.java

public static int getNumberOfDaysInPreviousMonth(Date someDayInCurrentMonth) {
    Calendar lastMonthCal = Calendar.getInstance();
    lastMonthCal.setTime(someDayInCurrentMonth);
    lastMonthCal.add(Calendar.MONTH, -1);
    return lastMonthCal.getActualMaximum(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static int getNumberOfWeeksInMonth(int year, int month) {
    Calendar calendar = Calendar.getInstance(Locale.FRANCE);
    calendar.set(year, month, 1, 0, 0, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    return calendar.getActualMaximum(Calendar.WEEK_OF_MONTH);
}