Calculates whether a date is between two dates.
The idea is that the difference between two dates can be calculated.
Compare the difference between 2 dates if the date3-date1 date is less than the date2-date1 then conflict otherwise no conflict
Import java. Text. parseexception;
Import java. Text. simpledateformat;
Import java. util. calendar;
Import java. util. date;
Import java. util. gregoriancalendar;
Public class test {
Private Static string date1 = "2010-01-01 ";
Private Static string date2 = "2014-09-01 ";
Private Static string date3 = "2016-05-23 ";
Public static void main (string [] ARGs ){
Simpledateformat formt = new simpledateformat ("yyyy-mm-dd ");
Calendar startcal = new gregoriancalendar ();
Calendar dealcal = new gregoriancalendar ();
Calendar endcal = new gregoriancalendar ();
Try {
Date d1 = formt. parse (date1 );
Date D2 = formt. parse (date2 );
Date D3 = formt. parse (date3 );
Startcal. settime (D1 );
Dealcal. settime (D2 );
Endcal. settime (D3 );
Long T1 = startcal. gettimeinmillis ();
Long T2 = dealcal. gettimeinmillis ();
Long T3 = endcal. gettimeinmillis ();
// Calculate the number of days for difference
Long days = (T2-t1)/(24x60*60*1000 );
Long temp = (T3-t1)/(24x60*60*1000 );
If (temp <days ){
System. Out. println ("date conflict ");
} Else
{
System. Out. println ("no conflict with date ");
}
} Catch (parseexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
}
}