Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date Formatting

 
Jignesh Gohel
Ranch Hand
Posts: 276
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Kj Reddy
Ranch Hand
Posts: 1704
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 276
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1704
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic