Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Convert String to Date  RSS feed

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone tell me what method will convert a String to a Date?
Thanks,
Frank
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
}
 
Trailboss
Posts: 22827
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See www.javaranch.com/common.html. Look for the GDate class.
 
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!