Example usage for java.util Calendar YEAR

List of usage examples for java.util Calendar YEAR

Introduction

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

Prototype

int YEAR

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

Click Source Link

Document

Field number for get and set indicating the year.

Usage

From source file:Main.java

public static int getCurrentYear() {
    return calendar.get(Calendar.YEAR);
}

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 w  w . j av a2  s  . co m
}

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 ww.  j av  a 2  s  .com*/
}

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 w w. j ava  2s. c  om*/
        return null;
    }
}

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 int getWeek(int year, int month) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MONTH, month - 1);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    return calendar.get(Calendar.DAY_OF_WEEK) - 1;
}

From source file:Main.java

public static String getYear() {
    Calendar calendar = Calendar.getInstance();
    return String.valueOf(calendar.get(Calendar.YEAR));
}

From source file:Main.java

public static void copyTo(Calendar from, Calendar to) {
    int year = from.get(Calendar.YEAR);
    int month = from.get(Calendar.MONTH);
    int day = from.get(Calendar.DAY_OF_MONTH);
    to.set(year, month, day);/*  w  ww.  j av  a 2  s .  co  m*/
    to.getTimeInMillis();
}

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 int getDaysByYearMonth(int year, int month) {

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