-3

Let's say I have two GregorianCalendar dates with the year, the month and the day from the month and they give me another GregorianCalendar date.

Is there a defined method to check if the given date is between the other two dates?

If not, would I need to start comparing the years, then the months and finally the day?

Unknown
  • 39
  • 2
  • 9

1 Answers1

1

This is a duplicate of many other questions.

Quick answer: avoid the old date-time classes and use only java.time classes.

Convert to java.time.ZonedDateTime.

ZonedDateTime zdt = myGregCal.toZonedDateTime();

Extract a date-only value.

LocalDate ld = zdt.toLocalDate();

Compare with other LocalDate objects by calling methods: compareTo, equals, isBefore, and isAfter.

Tip: search Stack Overflow for "Half-Open".

Tip: ! isBefore is a shorter way of saying "is equal to OR later than".

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154