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 getWeekFromDay(int year, int month, int day) {
    Calendar calendar = Calendar.getInstance();
    calendar.clear();/*www  . java  2s.com*/
    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

public static boolean isInSameDay(Calendar cl1, Calendar cl2) {
    if (cl1.get(Calendar.DAY_OF_YEAR) == cl2.get(Calendar.DAY_OF_YEAR)
            && cl1.get(Calendar.YEAR) == cl2.get(Calendar.YEAR)) {
        return true;
    }//from   w  w  w  . ja  v a 2  s  . co  m
    return false;
}

From source file:Main.java

public static int[] getYMD(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);//from ww w  .j  av  a  2s  .co m
    return new int[] { cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DATE) };
}

From source file:Main.java

public static LinkedList<String> getAniosVigencia() {
    Calendar c = Calendar.getInstance();
    int anio = c.get(Calendar.YEAR);

    LinkedList<String> anios = new LinkedList<String>();

    int amount = anio + 7;

    for (int i = anio; i < amount; i++) {
        anios.add("" + i);
    }//from  ww  w.  j  a v  a 2 s .c  om

    return anios;
}

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  ww .jav  a 2s.  co m*/
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();
}

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);
    c.set(Calendar.MONTH, m);/*w ww  .  jav a  2 s . c om*/
    c.set(Calendar.DATE, d);
    return c.get(Calendar.DAY_OF_WEEK) - 1;

}

From source file:Main.java

public static String getDateYYYYMM(int offset) {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.MONTH, offset);
    return calendar.get(Calendar.YEAR) + "-" + calendar.get(Calendar.MONTH);
}

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 String toDateString(Calendar date) {
    int day = date.get(Calendar.DAY_OF_MONTH);
    int month = date.get(Calendar.MONTH);
    int year = date.get(Calendar.YEAR);
    return day + "/" + (month + 1) + "/" + year;
}

From source file:Main.java

private static int getYearOfBirth(Date dateOfBirth) {
    Calendar dob = Calendar.getInstance();
    dob.setTime(dateOfBirth);//from  w  ww . java2 s  . c o  m
    return dob.get(Calendar.YEAR);
}