File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Date Format" Watch "Date Format" New topic

Date Format

Raj Mehta

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

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();

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,
which allows to specify a specific format.

I agree. Here's the link:
subject: Date Format
It's not a secret anymore!