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 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 .  ja va  2 s  .  c  om
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MONTH, month - 1);
    int days = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    return days;
}

From source file:Main.java

public static long getTimesMonthNextStart() {
    Calendar cal = Calendar.getInstance();
    cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
    cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
    cal.set(Calendar.HOUR_OF_DAY, 24);
    return cal.getTimeInMillis();
}

From source file:io.github.guaidaodl.pomodorotimer.utils.DateUtils.java

/**
 * ./*from  w w w. j  av  a 2  s  .  com*/
 *
 * Calendar  00:00:00
 */
@VisibleForTesting
static Pair<Long, Long> getMonthTime(Calendar calendar) {
    calendar.set(Calendar.DAY_OF_MONTH, 1);

    int dayCount = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    long startMilliSecondOfToday = calendar.getTimeInMillis();
    long endMilliSecondOfToday = startMilliSecondOfToday + dayCount * 24L * 60L * 60L * 1000L;

    return Pair.create(startMilliSecondOfToday, endMilliSecondOfToday);
}

From source file:Main.java

/**
 * Get last month end day//  www.j  av  a 2  s  . c om
 */
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

/**
 * Get next month end day//from ww w. j av  a 2  s . co 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 Date getEndDateOfMonth(int year, int month) throws ParseException {

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.YEAR, year);

    String enddat = year + "-" + (month + 1) + "-" + cal.getActualMaximum(Calendar.DATE);
    Date enddate = sdf.parse(enddat);

    return enddate;

}

From source file:Main.java

/**
 * Get the number of rows for the provided month
 * @param year year/*from  w w  w  . j  av a2  s.c  om*/
 * @param month month
 * @return number of rows
 */
public static int getNumOfRowsForTheMonth(int year, int month, int startDayOfTheWeek) {
    Calendar cal = Calendar.getInstance();
    cal.set(year, month, 1);
    MonthDisplayHelper displayHelper = new MonthDisplayHelper(year, month, startDayOfTheWeek);
    return displayHelper.getRowOf(cal.getActualMaximum(Calendar.DAY_OF_MONTH)) + 1;
}

From source file:Main.java

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

    date.set(Calendar.YEAR, year);
    date.set(Calendar.MONTH, month);
    date.set(Calendar.DAY_OF_MONTH, day);
    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:com.ekom.ekomerp.global.DateTimeUtils.java

public static Date getLastDayOfMonth(Date date) {
    Calendar calendar = getCalendarWithoutTime(date);
    calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
    return calendar.getTime();
}