Java utilities Util functions (Date Processing and http), javautil
/**
* Returns the day of the year based on the date.
* @ Param date
* @ Return
*/
Public static int orderDate (String dateStr ){
If (dateStr = null | dateStr. trim (). length () = 0) return 0;
Int dateSum = 0;
Int year = Integer. valueOf (dateStr. substring (0, 4 ));
Int month = Integer. valueOf (dateStr. substring (5, 7 ));
Int day = Integer. valueOf (dateStr. substring (8, 10 ));
For (int I = 1; I <month; I ++ ){
Switch (I ){
Case 1:
Case 3:
Case 5:
Case 7:
Case 8:
Case 10:
Case 12:
DateSum + = 31;
Break;
Case 4:
Case 6:
Case 9:
Case 11:
DateSum + = 30;
Break;
Case 2:
If (year % 4 = 0) & (year % 100! = 0) | (year % 400 = 0 ))
DateSum + = 29;
Else
DateSum + = 28;
}
}
Return dateSum = dateSum + day;
}
/**
* @ Get the formatted date (day) set between two dates
*/
Public static List <String> getMMDDList (String start, String end ){
SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd ");
SimpleDateFormat sdfout = new SimpleDateFormat ("MMdd ");
List <String> list = new ArrayList <String> ();
Try {
Date date_start = sdf. parse (start );
Date date_end = sdf. parse (end );
Date date = date_start;
Calendar cd = Calendar. getInstance ();
While (date. getTime () <= date_end.getTime ()){
List. add (sdfout. format (date ));
Cd. setTime (date );
Cd. add (Calendar. DATE, 1); // add a day
Date = cd. getTime ();
}
} Catch (Exception e ){
// TODO Auto-generated catch block
E. printStackTrace ();
}
Return list;
}
/**
*
* @ Method Name: testWsdlConnection
* @ Function Description: test whether the webservice address is available
* @ Return
*/
Public static boolean testWsdlConnection (String address ){
Boolean flag = false;
Try {
URL urlObj = new URL (address );
HttpURLConnection oc = (HttpURLConnection) urlObj. openConnection ();
Oc. setUseCaches (false );
Oc. setConnectTimeout (5000); // set the timeout value to 5 s.
Int status = oc. getResponseCode (); // Request status
If (200 = status ){
Return true;
}
} Catch (MalformedURLException e ){
E. printStackTrace ();
} Catch (IOException e ){
E. printStackTrace ();
} Catch (Exception e ){
E. printStackTrace ();
}
Return flag;
}