wood burning stoves*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Date Format
 
Similar Threads
Mock Exams for the new cert?
Help Needed in EL
Code for binary file to bitmap file conversion
Why is Refresh neccessary when loading the page?
How to pass Arraylist values from an actionClass to a JSP page