Example usage for java.util Calendar MONTH

List of usage examples for java.util Calendar MONTH

Introduction

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

Prototype

int MONTH

To view the source code for java.util Calendar MONTH.

Click Source Link

Document

Field number for get and set indicating the month.

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 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 int getMonth(Date date) {
    return (getCalendar(date).get(Calendar.MONTH) + 1);
}

From source file:Main.java

public static final int getMonthByMill(long mill) {
    Date curDate = new Date(mill);
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(curDate);//from w w  w .j  a  v  a 2 s.co m
    return calendar.get(java.util.Calendar.MONTH) + 1;
}

From source file:Main.java

public static String toYYYYMMDD(Calendar source) {
    if (source == null) {
        return "Can't toYYYYMMDDHHMMSS source null";
    }/*from w w w.j  av  a  2 s  .c o  m*/
    int YYYY = source.get(Calendar.YEAR);
    int MM = source.get(Calendar.MONTH);
    int DD = source.get(Calendar.DAY_OF_MONTH);

    return YYYY + "-" + MM + "-" + DD;
}

From source file:Main.java

public static Calendar buildCalendarInstance(final int year, final int month, final int dayOfMonth) {
    final Calendar c = Calendar.getInstance();
    c.clear();//from ww w  . j av  a2 s.  com

    c.set(Calendar.YEAR, year);
    c.set(Calendar.MONTH, month);
    c.set(Calendar.DAY_OF_MONTH, dayOfMonth);

    return c;
}

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: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 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:Util.java

public static String formatAsMySQLDatetime(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);//from ww  w  .j a  va2 s.c o  m

    int year = calendar.get(Calendar.YEAR);
    int month = calendar.get(Calendar.MONTH) + 1;
    int day = calendar.get(Calendar.DATE);

    int hours = calendar.get(Calendar.HOUR_OF_DAY);
    int minutes = calendar.get(Calendar.MINUTE);
    int seconds = calendar.get(Calendar.SECOND);

    return year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
}