aspose file tools*
The moose likes Beginning Java and the fly likes Date Format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Date Format" Watch "Date Format" New topic
Author

Date Format

Raj Mehta
Greenhorn

Joined: Apr 26, 2004
Posts: 11
How do I convert a String of the form "05272004" (MMDDYYYY) to a more meaningful format like 27th May, 2004.
Chengwei Lee
Ranch Hand

Joined: Apr 02, 2004
Posts: 884
Try reading java.text.DateFormat & see if you could work your answer out


SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
Raj Mehta
Greenhorn

Joined: Apr 26, 2004
Posts: 11
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

Joined: Feb 05, 2003
Posts: 234
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.
 
Don't get me started about those stupid light bulbs.
 
subject: Date Format