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 getWeekFromDay(int year, int month, int day) {
    Calendar calendar = Calendar.getInstance();
    calendar.clear();//w w w.j  a  v a  2 s .c  o m
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MONTH, month - 1);
    calendar.set(Calendar.DAY_OF_MONTH, day);
    return calendar.get(Calendar.WEEK_OF_YEAR);
}

From source file:Main.java

@NonNull
public static String getTime() {
    Calendar calendar = Calendar.getInstance();
    return calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-"
            + calendar.get(Calendar.DAY_OF_MONTH) + "  " + calendar.get(Calendar.HOUR_OF_DAY) + ":"
            + calendar.get(Calendar.MINUTE) + ":" + calendar.get(Calendar.SECOND);
}

From source file:Main.java

public static int getMonth(Date date) {
    calendar = Calendar.getInstance();
    calendar.setTime(date);//from   w w w  .java2  s .c om
    return calendar.get(Calendar.MONTH) + 1;
}

From source file:Main.java

public static String createCCPFileName() {
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(System.currentTimeMillis());

    int y = c.get(Calendar.YEAR);
    int m = c.get(Calendar.MONTH);
    int d = c.get(Calendar.DAY_OF_MONTH);
    int hour = c.get(Calendar.HOUR_OF_DAY);
    int minute = c.get(Calendar.MINUTE);
    int second = c.get(Calendar.SECOND);
    return y + "-" + m + "-" + d + "-" + hour + "-" + minute + "-" + second;
}

From source file:Main.java

public static int getYesterdayMonth() {
    long ts = System.currentTimeMillis() - 24 * 3600000;
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(ts);/*w w w  .ja  v a  2  s  .  c  o  m*/
    return calendar.get(Calendar.MONTH) + 1;
}

From source file:Main.java

public static String getMonthName(int month) {
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat month_date = new SimpleDateFormat("MMM");
    cal.set(Calendar.MONTH, month - 1);
    String month_name = month_date.format(cal.getTime());
    return month_name;
}

From source file:Main.java

public static String get_date() {
    int mYear;/*from   ww  w.jav a  2 s. c  o  m*/
    int mMonth;
    int mDay;

    final Calendar c = Calendar.getInstance();

    mYear = c.get(Calendar.YEAR);
    mMonth = c.get(Calendar.MONTH) + 1;
    mDay = c.get(Calendar.DAY_OF_MONTH);

    String result = String.format("%04d-%02d-%02d", mYear, mMonth, mDay);
    return result;
}

From source file:Main.java

public static int[] getWeekSunday(int year, int month, int day, int pervious) {
    int[] time = new int[3];
    Calendar c = Calendar.getInstance();
    c.set(Calendar.YEAR, year);/*from  ww w. j av  a2 s  . c o  m*/
    c.set(Calendar.MONTH, month);
    c.set(Calendar.DAY_OF_MONTH, day);
    c.add(Calendar.DAY_OF_MONTH, pervious);
    time[0] = c.get(Calendar.YEAR);
    time[1] = c.get(Calendar.MONTH) + 1;
    time[2] = c.get(Calendar.DAY_OF_MONTH);
    return time;

}

From source file:Main.java

public static String getDateString(long millitm) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(millitm);//w w w  .  ja  v a  2s. c om
    return (setZeroPad(cal.get(Calendar.YEAR)) + "/" + setZeroPad(cal.get(Calendar.MONTH)) + "/"
            + setZeroPad(cal.get(Calendar.DATE)) + " " + setZeroPad(cal.get(Calendar.HOUR_OF_DAY)) + ":"
            + setZeroPad(cal.get(Calendar.MINUTE)) + ":" + setZeroPad(cal.get(Calendar.SECOND)));
}

From source file:Main.java

/**
 * @return Return current year (IE 2015, 2016)
 *//*from w w  w.  j  a va  2 s . c  o m*/
public static int getCurrentMonth() {
    Calendar cal = Calendar.getInstance();
    int year = cal.get(Calendar.MONTH);
    year += 1; //January returns 0, December returns 11. Add one to return
    return year;
}