Java Date Compare by Year sameYear(Date date1, Date date2)

Here you can find the source of sameYear(Date date1, Date date2)

Description

same Year

License

Apache License

Declaration

public static boolean sameYear(Date date1, Date date2) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Calendar;
import java.util.Date;

public class Main {
    public static boolean sameYear(Date date1, Date date2) {

        if (date1 == null || date2 == null) {
            return false;
        }/*from   w  w w  . ja  v  a2  s. co  m*/

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date1);

        Calendar calendar2 = Calendar.getInstance();
        calendar.setTime(date2);

        return calendar.get(Calendar.YEAR) - calendar.get(Calendar.YEAR) == 0;
    }
}

Related

  1. sameYear(Date date1, Date date2)