Java Utililty Methods Date to Year

List of utility methods to do Date to Year

Description

The list of methods to do Date to Year are organized into topic(s).

Method

intgetYear(java.util.Date date)
get Year
java.util.Calendar c = java.util.Calendar.getInstance();
c.setTime(date);
return c.get(java.util.Calendar.YEAR);
IntegergetYear(java.util.Date today)
getYear: returns the year of the date
if (today != null) {
    java.util.Calendar c = java.util.Calendar.getInstance(Locale.GERMANY);
    c.setTime(today);
    return c.get(Calendar.YEAR);
} else {
    return null;
StringgetYear(String sdate)
get Year
String[] date = sdate.split("-");
return date[0];
intgetYear(String strDate)
get Year
Calendar cal = parseDateTime(strDate);
return cal.get(Calendar.YEAR) + 1900;
intgetYearAsInt(Date aDate)
get Year As Int
Calendar c = Calendar.getInstance();
c.setTime(aDate);
return c.get(Calendar.YEAR);
DategetYearBegin(final Date date)
get Year Begin
if (date == null) {
    return null;
Calendar cal = GregorianCalendar.getInstance();
cal.setTime(date);
cal.set(Calendar.MONTH, 0);
cal.set(Calendar.DATE, 1);
return cal.getTime();
...
intgetYearBetweenTwoDate(Date fdate, Date tdate)
Return offset years between specified begin date and end date
Calendar f = Calendar.getInstance();
f.setTime(fdate);
Calendar t = Calendar.getInstance();
t.setTime(tdate);
return t.get(Calendar.YEAR) - f.get(Calendar.YEAR);
IntegergetYearFromDate(Date date)
get Year From Date
Integer result = null;
if (date != null) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    result = calendar.get(Calendar.YEAR);
return result;
StringgetYearFromDate(Date date)
get Year From Date
if (date == null) {
    return null;
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return String.valueOf(cal.get(Calendar.YEAR));
StringgetYearMonth(Date date)
get Year Month
Calendar c = new GregorianCalendar();
c.setTime(date);
return c.get(Calendar.YEAR) + "-" + (c.get(Calendar.MONTH) + 1);