Public class test {
// The time ranges from to are missing: 01, 03, 04, 08, and 10)
Private Static string [] db_date =
{"2013-06-02", "2013-06-05", "2013-06-06"
, "2013-06-07", "2013-06-09 "};
// Result set
Private Static arraylist <string> dateresult = new arraylist <string> ();
Public static void main (string ARGs []) {
// Increase the time by one day
Simpledateformat SDF = new simpledateformat ("yyyy-mm-dd ");
Calendar yesterday = calendar. getinstance ();
Yesterday. Add (calendar. day_of_month, 1 );
String datestr = SDF. Format (yesterday. gettime ());
System. Out. println (datestr );
// Compare the date (How many days is the difference), and the time can also be compared
Calendar now = calendar. getinstance ();
System. Out. println (yesterday. compareto (now ));
// Convert string to time
Calendar calendar10 = calendar. getinstance ();
Calendar calendar5 = calendar. getinstance ();
// Process date data cyclically and complete the missing date. 10 is the number of days in a time period, and 5 is the number of days in the date set to be processed
Try {
Date = SDF. parse ("2013-06-01 ");
Calendar10.settime (date );
} Catch (parseexception e ){
E. printstacktrace ();
}
For (INT curr = 0; curr <10; curr ++ ){
Boolean dbdataexist = false;
Int Index = 0;
For (INT I = 0; I <5; I ++ ){
Try {
Date date2 = SDF. parse (db_date [I]);
Calendar5.settime (date2 );
} Catch (parseexception e ){
E. printstacktrace ();
}
If (calendar10.compareto (calendar5) = 0 ){
Dbdataexist = true;
Index = I;
Break;
}
}
If (dbdataexist ){
Dateresult. Add (db_date [Index]);
} Else {
Dateresult. Add (SDF. Format (calendar10.gettime ()));
}
// Restore calendar10
Calendar10.add (calendar. day_of_month, 1 );
}
// Print the result
For (string STR: dateresult ){
System. Out. println (STR );
}
}
}