Comparison of work experience periods

Source: Internet
Author: User

A pojo class is used to store time period objects.

Package com; import Java. util. date; public class timestore {public timestore () {} public timestore (date startdate, date enddate) {This. startdate = startdate; this. enddate = enddate;}/***** start time */private date startdate;/***** end time */private date enddate; public date getstartdate () {return startdate ;} public void setstartdate (date startdate) {This. startdate = startdate;} public date getenddate () {return enddate;} public void setenddate (date enddate) {This. enddate = enddate ;}}



Next, it is the most important part used to compare whether the time period is coincident.

Package com; import Java. text. simpledateformat; import Java. util. arraylist; import Java. util. date; import Java. util. list;/*** check whether the time period is coincident * @ author W. s **/public class datediffcompare {public static list <timestore> timestorelist = new arraylist <timestore> (); public static void main (string [] ARGs) {// Date startdate1 = formatdate ("2011/5"); // Date enddate1 = formatdate ("2012/5"); // Date startdate2 = formatdate ("2013/4 "); // Date enddate2 = formatdate ("2014/5"); // system. out. println (judgeisrightfulinline (startdate1, enddate1, startdate2, enddate2); timestorelist. add (New timestore (formatdate ("2011/5"), formatdate ("2012/5"); timestorelist. add (New timestore (formatdate ("2013/4"), formatdate ("2014/5"); Date startdate = formatdate ("2012/6 "); date enddate = formatdate ("2013/3"); system. out. println (judgedatediffisrightintimequeue (startdate, enddate ));} /*** determine whether the current time period is in the historical time queue * @ Param startdate * @ Param enddate * @ return */public static Boolean judgedatediffisrightintimequeue (date startdate, date enddate) {boolean result = true; For (timestore: timestorelist) {result = judgeisrightfulinline (startdate, enddate, timestore. getstartdate (), timestore. getenddate (); If (result = false) {break ;}} return result ;} /*** determine whether there is a cross between two dates * @ Param startdate1 * @ Param enddate1 * @ Param startdate2 * @ Param enddate2 * @ return */public static Boolean judgeisrightfulinline (date startdate1, date enddate1, date startdate2, date enddate2) {/*** the first working experience start time and end time are incorrect */If (startdate1.after (enddate1) {return false ;} /*** the start time and end time of the second stage of the work experience are incorrect */If (startdate2.after (enddate2) {return false ;} /*** second stage of work experience before the first stage of work experience */If (startdate1.after (startdate2) & startdate1.after (enddate2) {return true; /*** intersection between the second stage of work experience and the first stage of work experience */} else if (startdate1.after (startdate2) & startdate1.before (enddate2) {return false; /*** second stage of work experience between the first stage of work experience */} else if (startdate1.before (startdate2) & enddate2.before (enddate1) {return false; /*** intersection of the second and second sections of work experience */} else if (startdate2.before (enddate1) & enddate2.after (enddate1) {return false; /*** second stage of work experience after the first stage of work experience */} else if (startdate2.after (enddate1) & enddate2.after (enddate1) {return true ;} else if (startdate2.before (startdate1) & enddate2.after (enddate1) {return false;} else {system. out. println ("if the time range is equal (the start time and end time are the same), false is returned by default. "); Return false ;}} public static simpledateformat formatdate = new simpledateformat (" yyyy/mm "); /*** get date object * @ Param Str * @ return */public static date formatdate (string Str) {try {return formatdate. parse (STR);} catch (exception e) {e. printstacktrace ();} return NULL ;}}



If there are higher algorithms, you can post them for sharing.

Comparison of work experience periods

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.