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 getDays(int year, int month) {
    Calendar calendar = Calendar.getInstance();
    calendar.clear();/*from  w  w  w .  j  av  a  2  s  .  c  o  m*/
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MONTH, month - 1);
    int days = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    return days;
}

From source file:Main.java

public static Calendar setAsToday(Calendar aoCalendar) {
    Calendar loCalendar = Calendar.getInstance();
    aoCalendar.set(Calendar.YEAR, loCalendar.get(Calendar.YEAR));
    aoCalendar.set(Calendar.MONTH, loCalendar.get(Calendar.MONTH));
    aoCalendar.set(Calendar.DAY_OF_MONTH, loCalendar.get(Calendar.DAY_OF_MONTH));
    return aoCalendar;
}

From source file:Main.java

public static boolean isToday(Calendar calendar) {
    Calendar today = Calendar.getInstance();
    return today.get(Calendar.YEAR) == calendar.get(Calendar.YEAR)
            && today.get(Calendar.MONTH) == calendar.get(Calendar.MONTH)
            && today.get(Calendar.DAY_OF_MONTH) == calendar.get(Calendar.DAY_OF_MONTH);

}

From source file:Main.java

public static String getFirstDayOfMonth(int year, int month) {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.DAY_OF_MONTH, cal.getMinimum(Calendar.DATE));
    return new SimpleDateFormat("yyyy-MM-dd ").format(cal.getTime());
}

From source file:Main.java

public static String dataHoje() {
    Integer dia, mes, ano;//w w  w  . j a v  a  2s.c  om
    Calendar calendario = Calendar.getInstance();
    dia = calendario.get(Calendar.DAY_OF_MONTH);
    mes = calendario.get(Calendar.MONTH);
    ano = calendario.get(Calendar.YEAR);
    return dia + "/" + (mes + 1) + "/" + ano;
}

From source file:Main.java

public static int getDay(int y, int m, int d) {
    if (m < 0 || m > 11)
        return -1;

    Calendar c = Calendar.getInstance();
    c.set(Calendar.YEAR, y);/* w w  w . j  ava2 s.c  om*/
    c.set(Calendar.MONTH, m);
    c.set(Calendar.DATE, d);
    return c.get(Calendar.DAY_OF_WEEK) - 1;

}

From source file:Main.java

public static boolean isOver18(int year, int month, int day) {
    Calendar cal = Calendar.getInstance();
    int months = (cal.get(Calendar.YEAR) - year) * 12;
    months += cal.get(Calendar.MONTH) - month;
    int age = months / 12;

    if (age < 18 || (age == 18 && day > cal.get(Calendar.DAY_OF_MONTH))) {
        return false;
    }/*w  w w  .j  a v  a2s .c  o  m*/

    return true;
}

From source file:Main.java

public static String buildDateForUrl(Calendar calendar) {
    String day = (calendar.get(Calendar.DAY_OF_MONTH) < 10 ? "0" : "") + calendar.get(Calendar.DAY_OF_MONTH);
    String month = ((calendar.get(Calendar.MONTH) + 1) < 10 ? "0" : "") + (calendar.get(Calendar.MONTH) + 1);
    return calendar.get(Calendar.YEAR) + "" + month + "" + day;
}

From source file:Main.java

public static long intID() {
    Calendar c = Calendar.getInstance();

    int dia = c.get(Calendar.DAY_OF_MONTH);
    int ano = c.get(Calendar.YEAR) - 2010;
    int mes = c.get(Calendar.MONTH) + 1;

    int hora = c.get(Calendar.HOUR_OF_DAY);
    int minuto = c.get(Calendar.MINUTE);
    int segundo = c.get(Calendar.SECOND);
    int milisec = c.get(Calendar.MILLISECOND);

    return Long.parseLong("" + ano + mes + dia + hora + minuto + segundo + milisec);
}

From source file:Main.java

public static Date getDateFromYearMonthDay(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 w  w w  . ja  va 2 s .c  o m
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();
}