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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date conversion problem

Status
Not open for further replies.

wwworg

Programmer
Feb 10, 2006
35
CA
Hey guys

How can I get a month as "FEB" in java???
I know I can get the current date by

Date today1 = new Date();
and then get the current month using
int thisMonth = today1.getMonth()+1;
but this returns a number like "2" for Feb.
Is there anyway to retrieve a string like "FEB" instead of 2. Or there any function to convert them rather them having to hardcode with if and else's

What I really want to do is that I have a date in format (15-2-2006) and I want to convert it to (15-FEB-2006). How do i do this. I tried using SimpleDateFormatter like this

SimpleDateFormat format1 = new SimpleDateFormat("dd-MMM-yyyy");
java.util.Date dte = new java.util.Date(format1.parse(today1).getTime());

but it says that it cannot parse 15-2-2006

any thoughts

Thanks

 
Weird, second date parse question this week.

Code:
String todate= "15-2-2006";
SimpleDateFormat df = new SimpleDateFormat("dd-M-yyyy");
java.util.Date tDate = df.parse(todate);
df = new SimpleDateFormat("dd-MMM-yyyy");
String newdatestring = df.format(tDate).toUpperCase();
System.out.println(newdatestring);

Please try to post code with the tags [ignore]
Code:
[/ignore] in the future.

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

Part and Inventory Search

Sponsor

Back
Top