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 int getMonth(Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);
    return c.get(Calendar.MONTH);
}

From source file:Main.java

public static Date getDate(int year, int month, int day) {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.DAY_OF_MONTH, day);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);/*from ww w.ja  v a2s. com*/
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();
}

From source file:Main.java

public static Calendar getMonthsByOffset(Calendar c, int offset) {
    Calendar nextC = (Calendar) c.clone();
    nextC.add(Calendar.MONTH, offset);
    return nextC;
}

From source file:Main.java

public static String toYYYYMMDDHHMMSS(Calendar source) {
    if (source == null) {
        return "Can't toYYYYMMDDHHMMSS source null";
    }//  w  w w.  ja  va2s  .c  om
    int YYYY = source.get(Calendar.YEAR);
    int MM = source.get(Calendar.MONTH);
    int DD = source.get(Calendar.DAY_OF_MONTH);
    int HH = source.get(Calendar.HOUR_OF_DAY);
    int mm = source.get(Calendar.MINUTE);
    int SS = source.get(Calendar.SECOND);

    return YYYY + "-" + MM + "-" + DD + " " + HH + ":" + mm + ":" + SS;
}

From source file:Main.java

public static Integer getMonth(Date date) {
    if (date == null)
        return 0;
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/*from w  ww. ja v  a2  s  .c  o m*/
    return cal.get(Calendar.MONTH);
}

From source file:Main.java

public static String dateGraphLabelParser(long epoch) {
    Date date = new Date(epoch);
    Calendar cal = Calendar.getInstance();

    cal.setTime(date);// w  ww  . j a v a 2s.  com

    return String.format("%d/%d/%d", cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH),
            cal.get(Calendar.YEAR));
}

From source file:Main.java

public static int getMonth(int year, int week) {
    Calendar calendar = Calendar.getInstance();
    calendar.clear();//from   w w w .j  a  v a  2  s  .  co  m
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.WEEK_OF_YEAR, week);
    return calendar.get(Calendar.MONTH) + 1;
}

From source file:Main.java

public static int getNextMonth(Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);//w w  w  . j  av  a 2 s  .  co  m
    c.add(Calendar.MONTH, 1);
    return c.get(Calendar.MONTH);
}

From source file:Main.java

public static long getCountDownDays(int dayMonth, int month, int year) {

    Calendar thatDay = Calendar.getInstance();
    thatDay.set(Calendar.DAY_OF_MONTH, dayMonth);
    thatDay.set(Calendar.MONTH, month - 1); // 0-11 so 1 less
    thatDay.set(Calendar.YEAR, year);

    Calendar today = Calendar.getInstance();
    long diff = thatDay.getTimeInMillis() - today.getTimeInMillis();

    return diff / (24 * 60 * 60 * 1000);

}

From source file:Main.java

public static boolean isSameMonth(Calendar c1, Calendar c2) {
    if (c1 == null || c2 == null)
        return false;
    return (c1.get(Calendar.ERA) == c2.get(Calendar.ERA) && c1.get(Calendar.YEAR) == c2.get(Calendar.YEAR)
            && c1.get(Calendar.MONTH) == c2.get(Calendar.MONTH));
}