• Post Reply Bookmark Topic Watch Topic
  • New Topic

Covert String to Date  RSS feed

 
trupti nigam
Ranch Hand
Posts: 640
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get the date from the database table in VARCHAR format someting like "20070201" where it's in "yyyymmdd" format and I need to display it in "dd-Mon-yyyy" format.
Is there a simple function to convert it to java.util.Date format.

I have written a java function to do this but wanted to check if this can be achieved in simple steps.

Thanks
Trupti
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The usual way would be to use the SimpleDateFormat class. Something like

sdf1 = new SimpleDateFormat("yyyyMMdd")
Date dt = sdf1.parse("20070501")

sdf2 = new SimpleDateFormat("dd-MMM-yyyy")
String out = sdf2.format(dt)

Consult the javadocs for the exact syntax of the format pattern.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!