Here you can find the source of isSameDay(Date day1, Date day2)
Parameter | Description |
---|---|
from | a parameter |
to | a parameter |
public static boolean isSameDay(Date day1, Date day2)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; import java.util.Date; public class Main { /**//from w ww . j a v a2s. c o m * Checks if it is the same day in both dates * @param from * @param to * @return */ public static boolean isSameDay(Date day1, Date day2) { if (day1 == null || day1 == null) { throw new IllegalArgumentException("The date must not be null"); } Calendar cal1 = Calendar.getInstance(); cal1.setTime(day1); Calendar cal2 = Calendar.getInstance(); cal1.setTime(day2); return (cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA) && cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR)); } }