This week's book giveaways are in the Cloud and AI/ML forums.
We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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);
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!