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

/**
 * Get month days by year, month//w ww. jav a  2s  . c om
 *
 * @param year
 * @param month
 * @return
 */
public static int getMonthDays(int year, int month) {
    Calendar a = Calendar.getInstance();
    a.set(Calendar.YEAR, year);
    a.set(Calendar.MONTH, month - 1);
    a.set(Calendar.DATE, 1);
    a.roll(Calendar.DATE, -1);
    int maxDate = a.get(Calendar.DATE);
    return maxDate;
}

From source file:Main.java

public static boolean isSameDateInCalendar(Calendar calendar, Date date) {
    Calendar dateCalendar = Calendar.getInstance();
    dateCalendar.setTime(date);// www .j av a 2s.  c om
    return dateCalendar.get(Calendar.DAY_OF_MONTH) == calendar.get(Calendar.DAY_OF_MONTH)
            && dateCalendar.get(Calendar.MONTH) == calendar.get(Calendar.MONTH)
            && dateCalendar.get(Calendar.YEAR) == calendar.get(Calendar.YEAR);
}

From source file:DateTimeUtil.java

/**
 * //w w w  . j  a  v  a2s.c om
 * @param month
 * @param year
 * @return
 */
public static final int getlastDateofThisMonth(int month, int year) {
    Calendar calendar = Calendar.getInstance();
    if (year > -1) {
        calendar.set(Calendar.YEAR, year);
    }

    if (month > -1) {
        month--;
        calendar.set(Calendar.MONTH, month);
    }

    return calendar.getActualMaximum(Calendar.DATE);
}

From source file:Main.java

/**
 * Add date time with five years./*w  ww. j  a  v a2 s .  co m*/
 *
 * @param listing     the listing
 * @param currentTime the current time
 * @param isPast      true/false if past time
 */
private static void addDateTimeWithFiveYears(final List<Long> listing, final long currentTime,
        final boolean isPast) {
    final Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(currentTime);
    calendar.add(Calendar.MONTH, isPast ? -10 : 10);
    calendar.add(Calendar.YEAR, isPast ? -5 : 5);
    listing.add(calendar.getTimeInMillis());
}

From source file:Main.java

static boolean isSameDay(Calendar cal1, Calendar cal2) {
    if (cal1 == null || cal2 == null) {
        return false;
    }/*from   w  w  w  .  j a v  a 2s .com*/

    return (cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA)
            && 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

/**
 * returns 1 if calendar1 > calendar2 0 if calendar1 = calendar2 (same month
 * and year) -1 if calendar1 > calendar2
 * /*from  w  w w.j  a  va 2 s  .  c  om*/
 * @param calendar1
 * @param calendar2
 */
public static byte compareMonth(Calendar calendar1, Calendar calendar2) {
    byte dayBefore = 0;
    int findDiff = calendar1.get(Calendar.YEAR) - calendar2.get(Calendar.YEAR);
    if (findDiff > 0) {
        dayBefore = 1;
    } else if (findDiff < 0) {
        dayBefore = -1;
    } else {
        findDiff = calendar1.get(Calendar.MONTH) - calendar2.get(Calendar.MONTH);
        if (findDiff > 0) {
            dayBefore = 1;
        } else if (findDiff < 0) {
            dayBefore = -1;
        } else {

            dayBefore = 0;

        }
    }
    return dayBefore;
}

From source file:Main.java

/**
 * Add date time with almost two years./*from  w  w  w .j a  v  a  2  s  .  c o m*/
 *
 * @param listing     the listing
 * @param currentTime the current time
 * @param isPast      true/false if past time
 */
private static void addDateTimeWithAlmostTwoYears(final List<Long> listing, final long currentTime,
        final boolean isPast) {
    final Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(currentTime);
    calendar.add(Calendar.MONTH, isPast ? -10 : 10);
    calendar.add(Calendar.YEAR, isPast ? -1 : 1);
    listing.add(calendar.getTimeInMillis());
}

From source file:net.seratch.taskun.util.CalendarUtil.java

 public static Integer getYear(Calendar calendar) {
   Integer year = calendar.get(Calendar.YEAR);
   return year;
}

From source file:Main.java

/**
 * Encode a java date/time into a 16-bit encoded DOS date
 * //w ww .j a  va2  s .  c o m
 * @param javaDateTime
 * @return long
 */
public static int encodeDate(long javaDateTime) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(javaDateTime);
    return 512 * (cal.get(Calendar.YEAR) - 1980) + 32 * (cal.get(Calendar.MONTH) + 1) + cal.get(Calendar.DATE);
}

From source file:Main.java

public static String handleExpiration(@NonNull String dateYear) {

    String expiryString = dateYear.replace(SLASH_SEPERATOR, "");

    String text;//from www  .  j  a  v a2  s  .  c o m
    if (expiryString.length() >= 2) {
        String mm = expiryString.substring(0, 2);
        String yy;
        text = mm;

        try {
            if (Integer.parseInt(mm) > 12) {
                mm = "12"; // Cannot be more than 12.
            }
        } catch (Exception e) {
            mm = "01";
        }

        if (expiryString.length() >= 4) {
            yy = expiryString.substring(2, 4);

            try {
                Integer.parseInt(yy);
            } catch (Exception e) {

                Calendar calendar = Calendar.getInstance();
                int year = calendar.get(Calendar.YEAR);
                yy = String.valueOf(year).substring(2);
            }

            text = mm + SLASH_SEPERATOR + yy;

        } else if (expiryString.length() > 2) {
            yy = expiryString.substring(2);
            text = mm + SLASH_SEPERATOR + yy;
        }

    } else {
        text = expiryString;

    }

    return text;
}