Here you can find the source of sameYear(Date date1, Date date2)
Parameter | Description |
---|---|
date1 | a parameter |
date2 | a parameter |
public static boolean sameYear(Date date1, Date date2)
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { /**//from w ww.j a v a 2 s . c o m * Checks if the two given date have the same year. * * @param date1 * @param date2 * @return */ public static boolean sameYear(Date date1, Date date2) { if (date1 == null || date2 == null) { return false; } return getYear(date1) == getYear(date2); } /** * Extracts the year value from the given date. * * @param date * @return */ public static int getYear(Date date) { if (date == null) { return 1; } Calendar cal = Calendar.getInstance(); cal.setTime(date); return cal.get(Calendar.YEAR); } }