File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Convert String to Date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Convert String to Date" Watch "Convert String to Date" New topic

Convert String to Date

Frank Albright

Joined: Feb 19, 2000
Posts: 23
Can someone tell me what method will convert a String to a Date?
Todd M Bush

Joined: Apr 26, 2000
Posts: 22
The java.util.Date constructor will take a String. It will also take a year, month, day. (hour, min, and sec as well)
Date(String date)
Date(int year, int month, int day)
Carl Trusiak

Joined: Jun 13, 2000
Posts: 3340
This method has been deprecated. To create a Date object from a String object you have to use SimpleDateFormat parse method.
SimpleDateFormat sdfinDate = new SimpleDateFormat("MM/dd/yyyy");
java.util.Date actualDate = null;

actualDate = sdfinDate.parse("1/2/99");
catch(ParseException pe)
//handle exception

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
paul wheaton

Joined: Dec 14, 1998
Posts: 20973

See Look for the GDate class.

permaculture Wood Burning Stoves 2.0 - 4-DVD set
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Hoooooo Doggey - where ya headed pardner?
We don't seem to have the page yer lookin' fer.
Mebbe we're callin' it somethin else now.
We suggest you mosey on over to the
JavaRanch home page

"I'm not back." - Bill Harding, Twister
Ajay Kumar
Ranch Hand

Joined: Apr 28, 2000
Posts: 87
I think it has to do with Paul's obsession with punctuation. Just remove the last period after "...common.html" and U are right there.

Regds<BR>Ajay Kumar
I agree. Here's the link:
subject: Convert String to Date
It's not a secret anymore!