*
The moose likes Java in General and the fly likes converting string datetime object to date object. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "converting string datetime object to date object." Watch "converting string datetime object to date object." New topic
Author

converting string datetime object to date object.

amarshi mohanty
Ranch Hand

Joined: Jul 01, 2008
Posts: 110
Hi,

How to convert string date_time object to Date object.



SCJP (97%), SCWCD (95%))
Varun Chopra
Ranch Hand

Joined: Jul 10, 2008
Posts: 211
amarshi mohanty wrote:Hi,

How to convert string date_time object to Date object.



Look at java.text.DateFormat and parse method


-Varun -
(My Blog) - Online Certifications - Webner Solutions
Amit Vinod Dali
Ranch Hand

Joined: Apr 14, 2010
Posts: 42
import java.text.SimpleDateFormat;
import java.util.Date;


try
{
SimpleDateFormat dateDisplayFormat = new SimpleDateFormat("dd/MM/yyyy");
Date date = dateDisplayFormat.parse("2010-58-14 03:58:02");
}
catch (ParseException pe)
{
// Handle Exception here
}
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

Amid, please UseCodeTags. Also, that code won't work. The pattern clearly does not match the provided string.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

amarshi mohanty wrote:

That date looks really strange. What is it supposed to mean? The 14th day of the 58th month of 2010? Or the 58th day of the 14th month of 2010?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: converting string datetime object to date object.
 
Similar Threads
axis
String to date conversion
Need Help regarding -- org.xml.sax.SAXException: Invalid element
SOAP with attachments, 3 questions
Displaying the Date - Issue