Example usage for java.util Calendar getActualMinimum

List of usage examples for java.util Calendar getActualMinimum

Introduction

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

Prototype

public int getActualMinimum(int field) 

Source Link

Document

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

Usage

From source file:Main.java

/**
 * Get First Date of month// www.  ja v  a  2  s . c  o m
 */
public static Date getFirstDateOfMonth(int month, int year) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(year, month, 1);
    calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DATE));
    return calendar.getTime();
}

From source file:Main.java

public static void moveToCalendarDayJust(Calendar cal) { // 2011/11/17 00:00:00.000
    moveToCalendarDayJust(cal, cal.getActualMinimum(Calendar.HOUR_OF_DAY));
}

From source file:Main.java

/**
 * Get next month first day/*from  w  w w . j a v  a 2  s .c  om*/
 */
public static int getNextMonthFirstDay() {
    Calendar lastDate = Calendar.getInstance();
    lastDate.add(Calendar.MONTH, 1);
    lastDate.set(Calendar.DATE, 1);
    return lastDate.getActualMinimum(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

/**
 * Get last month first day//from  w  w w  .j  a v a  2 s . co m
 */
public static int getLastMonthFirstDay() {
    Calendar lastDate = Calendar.getInstance();
    lastDate.set(Calendar.DATE, 1);
    lastDate.add(Calendar.MONTH, -1);
    return lastDate.getActualMinimum(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static String getFirstDayOfLastMonth() {
    Calendar c = Calendar.getInstance();
    int month = c.get(Calendar.MONTH);
    c.set(Calendar.MONTH, month - 1);
    c.set(Calendar.DAY_OF_MONTH, c.getActualMinimum(Calendar.DAY_OF_MONTH));
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    return df.format(c.getTime());
}

From source file:Main.java

public static long getStartOfMonthMs(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.getActualMinimum(Calendar.DAY_OF_MONTH));
    date.set(Calendar.HOUR_OF_DAY, date.getActualMinimum(Calendar.HOUR_OF_DAY));
    date.set(Calendar.MINUTE, date.getActualMinimum(Calendar.MINUTE));
    date.set(Calendar.SECOND, date.getActualMinimum(Calendar.SECOND));
    date.set(Calendar.MILLISECOND, date.getActualMinimum(Calendar.MILLISECOND));
    return date.getTimeInMillis();
}

From source file:Main.java

public static long getTimesMonthStart() {
    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.getActualMinimum(Calendar.DAY_OF_MONTH));
    return cal.getTimeInMillis();
}

From source file:Main.java

public static long getTimesMonthMorning() {
    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.getActualMinimum(Calendar.DAY_OF_MONTH));
    return cal.getTimeInMillis();
}

From source file:Main.java

public static long getStartOfDayMs(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.getActualMinimum(Calendar.HOUR_OF_DAY));
    date.set(Calendar.MINUTE, date.getActualMinimum(Calendar.MINUTE));
    date.set(Calendar.SECOND, date.getActualMinimum(Calendar.SECOND));
    date.set(Calendar.MILLISECOND, date.getActualMinimum(Calendar.MILLISECOND));
    return date.getTimeInMillis();
}

From source file:com.ourlife.dev.common.utils.DateUtils.java

/**
 * ??//w ww  . j  a v a  2s .c  om
 * 
 * @param date
 * @return
 */
public static String[] getMonthBeginTimeAndEndTime(String date) {
    String[] dates = new String[2];
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(DateUtils.parseDate(date));
    calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
    dates[0] = DateUtils.formatDate(calendar.getTime(), "yyyy-MM-dd HH:mm:ss");

    calendar.add(Calendar.MONTH, 1);
    dates[1] = DateUtils.formatDate(calendar.getTime(), "yyyy-MM-dd HH:mm:ss");

    return dates;
}