Java utilities Util functions (Date Processing and http), javautil

Source: Internet
Author: User

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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.