/**
* Returns the current date according to the date is the day ordinal of a year
* @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 a formatted date (days) collection 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 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 timeout time 5s
int status = Oc.getresponsecode ();//Request Status
if (= = status) {
return true;
}
} catch (Malformedurlexception e) {
E.printstacktrace ();
} catch (IOException e) {
E.printstacktrace ();
}catch (Exception e) {
E.printstacktrace ();
}
return flag;
}
Several useful small util functions for Java (date processing and HTTP)