The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
April 2001

Advertisement

Advertisement

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.

Message:

Parsing dates

Posted by Jody Brown on April 12, 2001 at 8:18 AM

Lets say you have a string representing a date in the format:
String myDateStr = "2000-01-01"

You define a Simple date format object in the same format:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

Have a look at the API for all of the masks you can set up for a SimpleDateFormat.

Then, to parse your string into a date object, do the following:

Date myDate = null;
try {
myDate = sdf.parse(myDateStr);
} catch (ParseException pe) {
System.out.println("Error parsing date");
}

Hope this helps,

Regards,

Jody



Replies:
  • Dates Yoo-Jin Lee June 08, 2001 at 2:43 PM (0)

Sponsored Links



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