Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Date Formatting

 
Ranch Hand
Posts: 276
  • 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
 
Ranch Hand
Posts: 1704
  • 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
  • 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
  • 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);
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic