Converts a date string in unspecified format to a date object of the Java. util. date type.

Source: Internet
Author: User

Import Java. text. dateformat; <br/> Import Java. text. parseexception; <br/> Import Java. text. simpledateformat; <br/> Import Java. util. date; </P> <p> public class test {</P> <p>/** <br/> * test class main method <br> <br/> * Author: blueslee <br> <br/> * createdate: 2008-9-23 <br> <br/> * modifier: blueslee <br> <br/> * modifydate: <br> <br/> * version: 1.1 <br> <br/> * all right reserved. <br> <br/> * @ Param ARGs <br/> */<br/> Public static void main (string [] ARGs) {<br/> test = new test (); <br/> try {<br/> system. out. println (test. parsestringtodate ("03/2-3 03 hours "). tolocalestring (); <br/>} catch (parseexception e) {<br/> // todo auto-generated Catch Block <br/> E. printstacktrace (); <br/>}< br/>/** <br/> * converts date strings in unspecified formats to Java. util. date type date object <br> <br/> * Author: blueslee <br> <Br/> * createdate: <br> <br/> * modifier: blueslee <br> <br/> * modifydate: <br> <br/> * version: 1.1 <br> <br/> * all right reserved. <br> <br/> * @ Param date, date string to be converted <br/> * @ return <br/> * @ throws parseexception <br/> */<br/> Public date parsestringtodate (string date) throws parseexception {<br/> date result = NULL; <br/> string parse = date; <br/> parse = parse. replacefirst ("^ [0-9] {4} ([^ 0-9]?) "," YYYY $1 "); <br/> parse = parse. replacefirst (" ^ [0-9] {2} ([^ 0-9]?) "," YY $1 "); <br/> parse = parse. replacefirst (" ([^ 0-9]?) [0-9] {1, 2} ([^ 0-9]?) "," $1 MM $2 "); <br/> parse = parse. replacefirst (" ([^ 0-9]?) [0-9] {1, 2 }(?) "," $ 1dd $2 "); <br/> parse = parse. replacefirst (" () [0-9] {1, 2} ([^ 0-9]?) "," $ 1hh $2 "); <br/> parse = parse. replacefirst (" ([^ 0-9]?) [0-9] {1, 2} ([^ 0-9]?) "," $1mm $2 "); <br/> parse = parse. replacefirst (" ([^ 0-9]?) [0-9] {1, 2} ([^ 0-9]?) "," $ 1ss $2 "); </P> <p> dateformat format = new simpledateformat (PARSE); </P> <p> result = format. parse (date); </P> <p> return result; <br/>}< br/>

Http://linshiquan.javaeye.com/blog/280298

Related Article

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.