The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2000



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Date Formatting

Posted by Ivor Evans on November 02, 2000 at 4:30 AM

I am having trouble formatting dates that i am retrieving from a database.

The date is coming out of the database in this format:
2000-10-27 12:00:00.000

My code to format this looks like this

Locale loc = Locale.US;
Date docDate;

DateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss:SSS", loc);

try {
documentDate = ((String)((Vector)docDetails.elementAt(0)).elementAt(1)).trim();
System.out.println("Document Date " + documentDate);
// which is 2000-10-27 12:00:00.000
docDate = dateformat.parse(documentDate);
} catch (ParseException e) {
docDate = new Date();
System.out.println("An error has occurred trying to parse the date");
dateformat = new SimpleDateFormat("dd-MMM-yyyy");
//I then go on to format the date in this format

I am always getting an error and I am not sure why - My understanding of how it should work is obviously off the mark.

Ant helpo whatsoever is appreciated




Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us