Calculates whether a date is between two dates.

Source: Internet
Author: User

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 ();
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.