O'Reilly logo

Java™ Phrasebook by Timothy Fisher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Parsing Strings into Dates

String dateString = "January 12, 1952 or 3:30:32pm";
											DateFormat df = DateFormat.getDateInstance();
											Date date = df.parse(dateString);

The DateFormat object is used to parse a String and obtain a java.util.Date object. Getting a DateFormat object using the getDateInstance() method will create a DateFormat object using the normal date format for your country. You can then use the parse() method of the returned DateFormat object to parse a date string into a Date object, as shown in the phrase.

The parse() method will also accept a second parameter. The second parameter specifies a parse position in the string to be parsed. This specifies a starting point in the string to begin the parsing at.

The java.sql.Date, java.sql.Time ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required