Are two calendar objects represent the same local time.
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Calendar;
import java.util.Date;
public class Main {
public static boolean isSameLocalTime(Calendar cal1, Calendar cal2) {
if (cal1 == null || cal2 == null) {
throw new IllegalArgumentException("The date must not be null");
}
return (cal1.get(Calendar.MILLISECOND) == cal2.get(Calendar.MILLISECOND) &&
cal1.get(Calendar.SECOND) == cal2.get(Calendar.SECOND) &&
cal1.get(Calendar.MINUTE) == cal2.get(Calendar.MINUTE) &&
cal1.get(Calendar.HOUR) == cal2.get(Calendar.HOUR) &&
cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR) &&
cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA) &&
cal1.getClass() == cal2.getClass());
}
}
Home
Java Book
Runnable examples
Java Book
Runnable examples
Date Compare:
- Are two calendar objects represent the same local time.
- Are two dates or two calendars the same day
- Is a date the same day with another date
- Is a date after another date
- Is a date before another date
- Is date or calendar today's date
- Is a calendar or date after/before today or within a number of days in the future
- Compare two Date objects using compareTo
- Compares two dates are equals at day, month and year level, ignoring time
- Compare two times equals regardless of the date
- Compare two dates and times for equal
- Compare two Date