Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date format conversion

Status
Not open for further replies.

wwworg

Programmer
Feb 10, 2006
35
CA
Hey guys

I am using tomcat 5.5, J2SE 1.5 with Oracle 8i

Here is a function I have that converts a date like (18-06-2006) to (18-JUN-2006).

<%! public String changeDateFormat(String str) throws java.text.ParseException {
SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
java.util.Date tDate = new java.util.Date();
tDate = df.parse(str);
df = new SimpleDateFormat("dd-MMM-yyyy");
String date1 = df.format(tDate).toUpperCase();
return date1;
}
%>

What I want to be able to do is convert a date like (9999-12-30) to (30-DEC-9999). What Modifications do I need to make to this function to be able to do this. Because curently if I pass (9999-12-30) as a parameter, it gives an error saying "unparseable date".

Any help would be highly appreciated.

Thanks
 
Code tags - put your code between these tags :
[ignore]
Code:
[/ignore]

I've just run the code you posted above :

Code:
String s = t.changeDateFormat("01-02-2006");
System.out.println(s); 
s = t.changeDateFormat("2006-02-01");
System.out.println(s);

For both times, I get "01-FEB-2006", as expected, so it seems to be working ...

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top