Getdatestr,date type, conversion, date

Source: Internet
Author: User
/**  *  @param  StrDate  "Mm/dd/yyyyhh:mm:ss"  | |   "YYYYMMDDHHMMSS"  *   *  @return  DateStr  "Yyyy-mm-dd hh:mm:ss"  *  */public static string getdatebystr (STRING&NBSP;DATESTR)  throws ParseException{ if (datestr==null | |   ". Equals (Datestr)) {return " ";} string returndate = null; string format1 =  "Mm/dd/yyyyhh:mm:ss"; string format2 =  "YYYYMMDDHHMMSS"; string formatcn =  "Yyyy-mm-dd hh:mm:ss"; string formatechoise =format2; Char[] datechar = datestr.tochararray (); simpledateformat df =null; function of an expression: validation must be a number or space string pattern =  "[0-9]"; Pattern p = pattern.compile (pattern); for (int i=0;i<datechar.length;++i) {        matcher m  = p.matcher ("" "+datechar[i]);       &Nbsp; boolean bool = m.matches ();  if (datechar[i] !=  '/' &&bool) { Continue }else if (datechar[i] ==  '/') {formatechoise=format1; break;} else{return  "";}} Df = new simpledateformat (formatechoise); Date date = df.parse (DATESTR); Returndate = new simpledateformat (FORMATCN). Format (date). toString (); return returndate; }
The body of this function can add its own date format and then follow the Formate

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.