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 String getRemoteDir() {
    Calendar calendar = Calendar.getInstance();
    String str = calendar.get(Calendar.YEAR) + "_" + (calendar.get(Calendar.MONTH) + 1) + "_"
            + calendar.get(Calendar.DAY_OF_MONTH);
    return str;/*from   w w w.  ja  v a2 s .  c o m*/
}

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;/*from   w  ww.j  a v  a2s  .  c  o m*/
}

From source file:Main.java

public static int getCurrentMouth() {
    Calendar cal = Calendar.getInstance();
    int year = cal.get(Calendar.YEAR);
    int mouth = cal.get(Calendar.MONTH);
    int day = cal.get(Calendar.DATE);
    int currentIndex = (year - 1970) * 12 + mouth;
    return currentIndex;
}

From source file:Main.java

public static String formatCalendar(Calendar calendar) {
    if (calendar != null) {
        return calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-"
                + calendar.get(Calendar.DAY_OF_MONTH);
    } else {//from   w ww.  jav  a 2s . co  m
        return null;
    }
}

From source file:Main.java

public static int getUpMonth(Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);/*w  w w  .  j a  v a2  s.  c  o  m*/
    c.add(Calendar.MONTH, -1);
    return c.get(Calendar.MONTH);
}

From source file:Main.java

public static String getCurrentMonth() {
    Calendar calendar = Calendar.getInstance();
    int nMonth = calendar.get(Calendar.MONTH) + 1;
    if (nMonth < 10)
        return "0" + Integer.toString(nMonth);
    else/*from   w ww.j  a  v a  2 s. co  m*/
        return Integer.toString(nMonth);
}

From source file:Main.java

public static String getShortMonthYearDisplay(Calendar cal) {
    return cal.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.US) + " " + cal.get(Calendar.YEAR);
}

From source file:Main.java

public static int getDaysByYearMonth(int year, int month) {

    Calendar a = Calendar.getInstance();
    a.set(Calendar.YEAR, year);//from   www .  j a  va 2s . c  o  m
    a.set(Calendar.MONTH, month - 1);
    a.set(Calendar.DATE, 1);
    a.roll(Calendar.DATE, -1);
    return a.get(Calendar.DATE);
}

From source file:Main.java

public static int month() {
    return calendar().get(Calendar.MONTH) + 1;
}

From source file:Main.java

public static Date addMonth(Date date, int n) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/*w  w w.ja va  2s . co m*/
    cal.add(Calendar.MONTH, n);
    return cal.getTime();

}