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 boolean sameDate(Date date1, Date date2) {
    Calendar cal1 = Calendar.getInstance();
    Calendar cal2 = Calendar.getInstance();
    cal1.setTime(date1);/* ww w .  j  a  v a2  s  .  co m*/
    cal2.setTime(date2);
    return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)
            && cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR);
}

From source file:Main.java

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

From source file:Main.java

public static int getYearFromDate(Date date) {
    helperCalendar.setTime(date);
    return helperCalendar.get(Calendar.YEAR);
}

From source file:Main.java

public static String getMySQLDateFormat() {

    //Membuat string tanggal sekarang
    Calendar now = Calendar.getInstance();
    int month = now.get(Calendar.MONTH) + 1;
    int day = now.get(Calendar.DAY_OF_MONTH);
    int year = now.get(Calendar.YEAR);

    return year + "-" + month + "-" + day;

}

From source file:Main.java

public static boolean isSameDay(Date date1, Date date2) {
    Calendar cal1 = Calendar.getInstance();
    cal1.setTime(date1);//from  w  w  w. j a  v a 2  s .c o  m

    Calendar cal2 = Calendar.getInstance();
    cal2.setTime(date2);

    return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)
            && cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR);
}

From source file:Main.java

public static boolean datesOnSameDay(Date date1, Date date2) {
    Calendar cal1 = Calendar.getInstance();
    Calendar cal2 = Calendar.getInstance();
    cal1.setTime(date1);/*  w  ww  . ja  va  2 s  .c om*/
    cal2.setTime(date2);
    return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)
            && cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR);
}

From source file:Main.java

public static Calendar getRandomApodDate() {
    Calendar newCalendar = Calendar.getInstance();

    Calendar today = Calendar.getInstance();
    int currentYear = today.get(Calendar.YEAR);
    int currentMonth = today.get(Calendar.MONTH);
    int currentDay = today.get(Calendar.DATE);

    int firstApodYear = 1995;
    int firstApodMonth = 5;
    int firstApodDay = 20;

    Random rnd = new Random();
    int newYear = rnd.nextInt(currentYear - firstApodYear + 1) + firstApodYear;

    int minMonth = 0;
    int maxMonth = 11;
    if (newYear == firstApodYear)
        minMonth = firstApodMonth;/*from  w ww .  ja  v a  2  s . co m*/
    if (newYear == currentYear)
        maxMonth = currentMonth;
    int newMonth = rnd.nextInt(maxMonth - minMonth + 1) + minMonth;

    newCalendar.set(newYear, newMonth, 1);

    int minDay = 1;
    int maxDay = newCalendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    if (newYear == firstApodYear && newMonth == firstApodMonth)
        minDay = firstApodDay;
    if (newYear == currentYear && newMonth == currentMonth)
        maxDay = currentDay;
    int newDay = rnd.nextInt(maxDay - minDay + 1) + minDay;

    newCalendar.set(newYear, newMonth, newDay);
    return newCalendar;
}

From source file:Main.java

private static int dateCompareTo(Calendar calEnd, Calendar calStart) {
    if (calEnd.get(Calendar.DAY_OF_YEAR) == calStart.get(Calendar.DAY_OF_YEAR)) {
        if (calEnd.get(Calendar.YEAR) == calStart.get(Calendar.YEAR)) {
            return 0;
        } else {/*from  w  ww  .  j  a  v a 2  s .c o  m*/
            if (calEnd.get(Calendar.YEAR) > calStart.get(Calendar.YEAR)) {
                return 1;
            } else {
                return -1;
            }
        }
    } else {
        if (calEnd.get(Calendar.YEAR) == calStart.get(Calendar.YEAR)) {
            if (calEnd.get(Calendar.DAY_OF_YEAR) > calStart.get(Calendar.DAY_OF_YEAR)) {
                return 1;
            } else {
                return -1;
            }
        } else if (calEnd.get(Calendar.YEAR) > calStart.get(Calendar.YEAR)) {
            return 1;
        } else {
            return -1;
        }

    }
}

From source file:Main.java

public static boolean isSameMonth(Date date1, Date date2) {
    Calendar cal1 = Calendar.getInstance();
    cal1.setTime(date1);/*from   w  ww.  j  av a2  s. co  m*/

    Calendar cal2 = Calendar.getInstance();
    cal2.setTime(date2);

    return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)
            && cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH);
}

From source file:Main.java

public static int getYear(Calendar c) {
    return c.get(Calendar.YEAR);
}