Here you can find the source of isTheSameDay(Calendar dayOne, Calendar dayTwo)
Parameter | Description |
---|---|
dayOne | the day one |
dayTwo | the day two |
public static boolean isTheSameDay(Calendar dayOne, Calendar dayTwo)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.TimeZone; public class Main { /**/* w ww. ja va 2 s. c o m*/ * Check if the calendars are referring to the same day * * @param dayOne * the day one * @param dayTwo * the day two * @return true if the days are equal */ public static boolean isTheSameDay(Calendar dayOne, Calendar dayTwo) { boolean result = false; if (dayOne == null || dayTwo == null) { result = false; } else { result = (dayTwo.get(Calendar.DAY_OF_YEAR) == dayOne.get(Calendar.DAY_OF_YEAR)) && (dayTwo.get(Calendar.YEAR) == dayOne.get(Calendar.YEAR)); } return result; } /** * Check if the dates are referring to the same day * * @param dayOne * the day one * @param dayTwo * the day two * @return true if the days are equal */ public static boolean isTheSameDay(Date dayOne, Date dayTwo) { return isTheSameDay(dayOne, dayTwo, null); } /** * Check if the dates are referring to the same day and add set the timezone * * @param dayOne * the day one with respect to the timezone * @param dayTwo * the day two with respect to the timezone * @param userTimeZone * for timezone specific comparison; can be null * @return true if the days are equal */ public static boolean isTheSameDay(Date dayOne, Date dayTwo, TimeZone userTimeZone) { Calendar one = new GregorianCalendar(); Calendar two = new GregorianCalendar(); one.setTime(dayOne); two.setTime(dayTwo); if (userTimeZone != null) { one.setTimeZone(userTimeZone); two.setTimeZone(userTimeZone); } return isTheSameDay(one, two); } }