Here you can find the source of sameDay(Date date1, Date date2)
Parameter | Description |
---|---|
date1 | a date |
date2 | another date |
true
of date1
and date2
are in the same day, false
otherwise.
public static boolean sameDay(Date date1, Date date2)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { /**// ww 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 day, * <code>false</code> otherwise. */ public static boolean sameDay(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) && c1.get(Calendar.DAY_OF_YEAR) == c2.get(Calendar.DAY_OF_YEAR); } }