aspose file tools*
The moose likes Java in General and the fly likes Date Formatting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Date Formatting" Watch "Date Formatting" New topic
Author

Date Formatting

Jignesh Gohel
Ranch Hand

Joined: Dec 28, 2004
Posts: 276
Hi,

I have a date in the form of string like 2006-03-17.

Now i want to convert it to format 17MAR2006 or some other .
So how can i do this??

Thanks,
Jignesh


Regards,
Jignesh

The Art Of Life Is To Know When To Be Useless And When To Be Useful - CHUANG TZU
Kj Reddy
Ranch Hand

Joined: Sep 20, 2003
Posts: 1704
You can use java.text.DateFormat object methods.

Refer the api they explained how to use it:
http://java.sun.com/j2se/1.4.2/docs/api/java/text/DateFormat.html
Jignesh Gohel
Ranch Hand

Joined: Dec 28, 2004
Posts: 276
Thanks once again Mr Reddy.

The string date which i am getting from the database is:
2006-03-14 00:00:00.000

I did the following thing .

SimpleDateFormat dt_Format = new SimpleDateFormat("dd-MMM-yyyy");
Date d_t = dt_Format.parse(pay_Date);
String dt = dt_Format.format(d_t);

But when executing my jsp page teh tomcat is throwing the error:

Unparseable date: "2006-03-14 00:00:00.0"


So what to do now??

Jignesh
Kj Reddy
Ranch Hand

Joined: Sep 20, 2003
Posts: 1704
Jignesh,

Try this:
String dateString = "2006-03-14 00:00:00.000"; // i guess u get it from db
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date date = format.parse(dateString);
format.applyPattern("dd-MM-yyyy");
String dt = format.format(date);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Date Formatting