Convert String Date to another pattern
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Aaron_Rowe
Posted On:   Friday, July 9, 2004 11:51 AM

I have a String date that looks like this:

17-JUL-04

I want to convert it to a String date that looks like this:

20040717

How do I do that?

Thanks.

Re: Convert String Date to another pattern

Posted By:   Anonymous  
Posted On:   Thursday, July 15, 2004 04:20 AM

I want to convert date like 25/04/1955 to April 25,1955. How can i do it? thanks..

Re: Convert String Date to another pattern

Posted By:   Sean_Ruff  
Posted On:   Friday, July 9, 2004 12:54 PM


String val = "17-JUL-04";

SimpleDateFormat from = new SimpleDateFormat("dd-MMM-yy");
SimpleDateFormat to = new SimpleDateFormat("yyyyMMdd");
try {
Date dte = from.parse(val);
String res = to.format(dte);
System.out.println(res);
} catch (Exception e) {
}

Re: Convert String Date to another pattern

Posted By:   Marc_Kapke  
Posted On:   Friday, July 9, 2004 12:19 PM

I think you should be able to use the parse() function in the the java.text.DateFormat



Otherwise, you could write a very simple parser of your own that would convert the date. Make a helper method that grabs each part of the date and converts it(where needed) and concatenates to the end of your needed date string.


Just a thought. Check the API under DateFormat for more info. You may also want to look at the Calendar class as well. The Date class in Java.util is deprecated, so I wouldn't recommend using its methods.


Good luck and happy programming!

About | Sitemap | Contact