Monday, July 27, 2009

How to convert a string to Date in Java?

I need to convert a string pattern 01/10/2005 14:36:47-02:00 into a date object using Java. I could convert several other formats, but not this. Note the : in the timezone (-02:00).





Any help is appreciated.

How to convert a string to Date in Java?
simple





Date date=null;


try {


SimpleDateFormat df=new SimpleDateFormat("MM/dd/yyyy");


date=df.parse("10/22/2005");


}


catch (Exception err) {


}


System.out.println ("Date: "+date); // will print the Date object
Reply:Remove the Last 6 Characters before converting. Report It


id cards

No comments:

Post a Comment