*
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Convert String to Date" Watch "Convert String to Date" New topic
Author

Convert String to Date

Frank Albright
Greenhorn

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

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
Sheriff

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;

try
{
sdfinDate.setLenient(true);
actualDate = sdfinDate.parse("1/2/99");
}
catch(ParseException pe)
{
//handle exception
}

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

Joined: Dec 14, 1998
Posts: 20545
    ∞

See www.javaranch.com/common.html. Look for the GDate class.


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

Joined: Jan 30, 2000
Posts: 18671
Eh?
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
Jim,
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.
www.javaranch.com/common.html
Ajay


Regds<BR>Ajay Kumar
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Convert String to Date