• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Date Formatting

 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
 
Why does your bag say "bombs"? The reason I ask is that my bag says "tiny ads" and it has stuff like this:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic