List of utility methods to do Year
Calendar | createCalendarAtBeginningOfYear(int year) create Calendar At Beginning Of Year final GregorianCalendar calendar = createUtcCalendar();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, 0);
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
...
|
Integer | currentYear() current Year GregorianCalendar gFechaActual = new GregorianCalendar(); return gFechaActual.get(GregorianCalendar.YEAR); |
int | daysInYear(int year) days In Year Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR, year);
return c.getActualMaximum(Calendar.DAY_OF_YEAR);
|
double | differenceInYears(final Calendar a, final Calendar b) Calculates difference in years between to dates. final long millisDif = a.getTimeInMillis() - b.getTimeInMillis(); return millisDif / MILLISECONDS_PER_YEAR; |
int | diffYears(Date day1, Date day2) diff Years Calendar cal = Calendar.getInstance(); cal.setTime(day1); int startYear = cal.getWeekYear(); cal.clear(); cal.setTime(day2); int endYear = cal.getWeekYear(); int diffyears = endYear - startYear; return diffyears; ... |
boolean | IsInLeapYear(Date date1) Indicates whether the year in the specified date is in a leap year. GregorianCalendar cal = new GregorianCalendar(); cal.setTime(date1); return cal.isLeapYear(cal.get(cal.YEAR)); |
boolean | isLeapYear(int year) is Leap Year Calendar calendar = Calendar.getInstance(); calendar.set(year, 2, 1); calendar.add(Calendar.DATE, -1); if (calendar.get(Calendar.DAY_OF_MONTH) == 29) { return true; } else { return false; |
Date | nextYears(int diff) next Years return add(new Date(), Calendar.YEAR, diff); |
boolean | sameYear(Date date1, Date date2) same Year if (date1 == null || date2 == null) throw new IllegalArgumentException("'date1' or 'date2' was null"); Calendar c1 = Calendar.getInstance(); c1.setTime(date1); Calendar c2 = Calendar.getInstance(); c2.setTime(date2); return c1.get(Calendar.YEAR) == c2.get(Calendar.YEAR); |
String | yearAndSeason(Date date) year And Season final Calendar cal = Calendar.getInstance(); cal.setTime(date); return yearAndSeason(cal); |