/**
* Convert string dates to dates in the specified format
* @ Param Str
* @ Return
* @ Throws parseexception
*
* @ Author zhaozj
*/
Public static date stringparsedate (string STR, string format) throws parseexception {
String strformat = constants. GetType (STR );
Simpledateformat SDF = new simpledateformat (strformat );
Simpledateformat sdf1 = new simpledateformat (format );
If (STR = NULL | "". Equals (STR )){
Return NULL;
} Else {
Date = SDF. parse (STR );
String strdate = sdf1.format (date );
Return sdf1.parse (strdate );
}
}
// Get date format based on string date
Public static string GetType (string date ){
String result = NULL;
If (date. Matches ("\ D {4}-\ D {2}-\ D {2}
\ D {2 }:\\ d {2 }:\\ d {2}. \ D + ")){
Result = constants. date_model_1;
} Else if (date. Matches ("\ D {4}-\ D {2}-\ D {2}
\ D {2 }:\\ d {2 }:\\ d {2 }")){
Result = constants. date_model_2;
} Else if (date. Matches ("\ D {4}-\ D {2}-\ D {2}
\ D {2 }:\\ d {2 }")){
Result = constants. date_model_3;
} Else if (date. Matches ("\ D {4}-\ D {2}-\ D {2}
\ D {2 }")){
Result = constants. date_model_4;
} Else if (date. Matches ("\ D {4}-\ D {2}-\ D {2 }")){
Result = constants. date_model_5;
} Else if (date. Matches ("\ D {4}-\ D {2 }")){
Result = constants. date_model_6;
} Else if (date. Matches ("\ D {14}. \ D + ")){
Result = constants. date_model_7;
} Else if (date. Matches ("\ D {14 }")){
Result = constants. date_model_8;
} Else if (date. Matches ("\ D {12 }")){
Result = constants. date_model_9;
} Else if (date. Matches ("\ D {10 }")){
Result = constants. date_model_10;
} Else if (date. Matches ("\ D {8 }")){
Result = constants. date_model_11;
} Else if (date. Matches ("\ D {6 }")){
Result = constants. date_model_12;
} Else if (date. Matches ("\ D {4}/\ D {2}/\ D {2}
\ D {2 }:\\ d {2 }:\\ d {2}. \ D + ")){
Result = constants. date_model_13;
} Else if (date. Matches ("\ D {4}/\ D {2}/\ D {2}
\ D {2 }:\\ d {2 }:\\ d {2 }")){
Result = constants. date_model_14;
} Else if (date. Matches ("\ D {4}/\ D {2}/\ D {2}
\ D {2 }:\\ d {2 }")){
Result = constants. date_model_15;
} Else if (date. Matches ("\ D {4}/\ D {2}/\ D {2}
\ D {2 }")){
Result = constants. date_model_16;
} Else if (date. Matches ("\ D {4}/\ D {2}/\ D {2 }")){
Result = constants. date_model_17;
} Else if (date. Matches ("\ D {4}/\ D {2 }")){
Result = constants. date_model_18;
}
Return result;
}