Here you can find the source of sameYear(Date date1, Date date2)
Parameter | Description |
---|---|
date1 | a date |
date2 | another date |
true
of date1
and date2
are in the same year, false
otherwise.
public static boolean sameYear(Date date1, Date date2)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { /**/* w w w .j a va2s . c o m*/ * @param date1 a date * @param date2 another date * @return <code>true</code> of <code>date1</code> and <code>date2</code> are in the same year, * <code>false</code> otherwise. */ public static boolean sameYear(Date date1, Date date2) { 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); } }