Boolean intervalContainsToday = ( ! today.isBefore( start ) ) && today.isBefore( stop ) ;
DateTimeFormatter f = DateTimeFormatter.ofPattern( "dd-MM-uuuu" );
DateTimeFormatter formatter = DateTimeFormat.forPattern( "dd-MM-yyyy" );
Dates: 2010-02-22 2010-04-07 2010-12-25
LocalDate localDate1 = formatter.parseLocalDate( string1 );
LocalDate localDate2 = formatter.parseLocalDate( string2 );
LocalDate localDate3 = formatter.parseLocalDate( string3 );
boolean is1After2 = localDate1.isAfter( localDate2 );
boolean is2Before3 = localDate2.isBefore( localDate3 );
LocalDate start = LocalDate.parse( "22-02-2010" , f );
LocalDate stop = LocalDate.parse( "25-12-2010" , f );
LocalDate today = LocalDate.now( ZoneId.of( "America/Montreal" ) ) ;
Boolean isBetween =
( ! today.isBefore( localDate1 ) ) // not-before is short for is-equal-to or later-than.
today.isBefore( localDate3 ) ;
String string1 = "22-02-2010";
String string2 = "07-04-2010";
String string3 = "25-12-2010";
System.out.println( "Dates: " + localDate1 + " " + localDate2 + " " + localDate3 );
System.out.println( "is1After2 " + is1After2 );
System.out.println( "is2Before3 " + is2Before3 );
ZoneId z = ZoneId.of( "America/Montreal" );
LocalDate today = LocalDate.now( z );
boolean is2Between1And3 = ( ( localDate2.isAfter( localDate1 ) ) && ( localDate2.isBefore( localDate3 ) ) );
Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport.
Part of the standard Java API with a bundled implementation.
durationFormat: PnYnMnDTnHnMnSExample: P3Y6M4DT12H30M5S(Means three years, six months, four days, twelve hours, thirty minutes, and five seconds)
A time zone is crucial in determining a date. For any given moment, the date varies around the globe by zone. For example, a few minutes after midnight in Paris France is a new day while still yesterday in Montral Qubec.
As your input strings are non-standard format, we must define a formatting pattern to match.
By the way, that is a bad choice of format for a text representation of a date or date-time value. Whenever possible, stick with the standard ISO 8601 formats. ISO 8601 formats are unambiguous, understandable across human cultures, and are easy to parse by machine.
Define a formatter describing the input strings
For a date-only value, the standard format is YYYY-MM-DD. Note how this format has the benefit of being chronological when sorted alphabetically.
Half-open approach, where beginning is inclusive while ending is exclusive.
If you are working with spans of time, I suggest exploring in Joda-Time the classes: Duration, Interval, and Period. Methods such as overlap and contains make comparisons easy.
If you truly want a date without any time portion and no time zone, then use the LocalDate class in Joda-Time. That class provides methods of comparison including compareTo (used with Java Comparators), isBefore, isAfter, and isEqual.
In date-time work, usually best to define a span of time by the Half-Open approach where the beginning is inclusive while the ending is exclusive. So we want to know if today is the same or later than the start and also before the stop. A briefer way of saying is the same or later than the start is not before the start.
Joda-Time classes can work with strings in both those formats, both as input (parsing) and output (generating strings).
Joda-Time performs comparisons using the Half-Open approach where the beginning of the span is inclusive while the ending is exclusive. This approach is a wise one for handling spans of time. Search StackOverflow for more info.
Other answers are correct with regard to the bundled java.util.Date and java.util.Calendar classes. But those classes are notoriously troublesome. So here's some example code using the Joda-Time 2.3 library.
See the Answer by gstackoverflow showing the list of comparison methods you can call.
So see if the second is between the other two (exclusively, meaning not equal to either endpoint)
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
The LocalDate class represents a date-only value without time-of-day and without time zone.
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval, YearWeek, YearQuarter, and more.
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date, Calendar, & SimpleDateFormat.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
UPDATE: This Joda-Time section below is left intact as history. The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
Use formatter to parse the strings into LocalDate objects
Use that to parse the input strings.