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

Converting the date format  RSS feed

 
poornima balagopal
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have a string with a value "12-12-03" or a string which contain a date in the above format.
I want to convert 12-12-03(which is a String ) into 12-Dec-03 format.
If anybody knows the simple way to do this please help me .
This is a small outline what i am doing
String startdate=objForm.getStartDate();
ArrayList paramList=new ArrayList();
paramList.add(0,startdate);
The value in the String startDate will be in the format i mentioned above which i have to convert as 12-dec-03 format before adding into the ArrayList.
So Please help me . Thanks in advance
 
Anurag Mishra
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
pls use SimpleDateFormat class in package java.text.SimpleDateFormat
youcan check details in jdk docs and can use same to get date in a format whatever you want.
thanks
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A hint - you might use two SimpleDateFormat objects - one to specify your input format for parsing, and another to specify your output format.
For a completely different approach, you might break your input string on dashes into three strings (see StringTokenizer), look up the "Dec" string using the "12" string (see Map) and then put the parts back together.
Let us know how it works out!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!