Protected List getYears (Long userno, String end) throws Exception {List returnList = new ArrayList (); // obtain the year (obtain the year List based on the current employee ID, release schedule, and log earliest time) List cjsjSch = this. getBaseBiz (). getSchHasYear (userno, end); // the data stored in the cjsjSch set is Date-type List cjsjLog = this. getBaseBiz (). getLogHasYear (userno, end); // cyclically obtain the calendar year for (int I = 0; I <cjsjSch. size (); I ++) {Date sj = (Date) cjsjSch. get (I); // The Object returned by the get (int index) method in the cjsjSch set is of the Object type and must be forcibly converted to String sj_strString = DateUtils. dateToStr (sj); // convert Date to String returnList. add (sj_strString.substring (0, 4);} // obtain the log year in a loop (int j = 0; j <cjsjLog. size (); j ++) {Date sj = (Date) cjsjLog. get (j); String sj_strString = DateUtils. dateToStr (sj); returnList. add (sj_strString.substring (0, 4);} // remove returnList = remo (returnList) for duplicate years; // sort Collections in ascending order. sort (returnList); // sort Collections in descending order. reverse (returnList); return returnList ;}
Conversion between short-time format strings and short-time formats
/*** Convert the short-time format to the string yyyy-mm-dd ** @ Param datedate * @ Param K * @ return */public static string datetostr (Java. util. date datedate) {simpledateformat formatter = new simpledateformat ("yyyy-mm-dd"); string datestring = formatter. format (datedate); Return datestring ;} /*** convert a short-time string to a time string in yyyy-mm-dd *** @ Param strdate * @ return */public static date strtodate (string strdate) {If (strdate = NULL) {return NULL;} simpledateformat formatter = new simpledateformat ("yyyy-mm-dd"); parseposition Pos = new parseposition (0 ); date strtodate = formatter. parse (strdate, POS); Return strtodate ;} /*** convert short-time format strings to time yyyy *** @ Param strdate * @ return */public static date strtodateyyyy (string strdate) {If (strdate = NULL) {return NULL;} simpledateformat formatter = new simpledateformat ("YYYY"); parseposition Pos = new parseposition (0); Date strtodate = formatter. parse (strdate, POS); Return strtodate ;}