• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date Format

 
Raj Mehta
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I convert a String of the form "05272004" (MMDDYYYY) to a more meaningful format like 27th May, 2004.
 
Chengwei Lee
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try reading java.text.DateFormat & see if you could work your answer out
 
Raj Mehta
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had already taken a look at DateFormat class. And the only thing I thought would solve my problem was the Parse(String) method. But when I do this :

java.text.DateFormat df = java.text.DateFormat.getDateInstance();
df.parse("050272004");

I get the following error : Unparseable date: "06202004".

Any other suggestions ??
 
bart zagers
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your approach, you did not (have) to specify the format of the string that you wanted to parse. It uses a default format that probably does not correspond to the one of your given string.

Did you notice that java.text.DateFormat is an abstract class?
Take a look at its subclass,
java.text.SimpleDateFormat,
which allows to specify a specific format.

Bart.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic