aspose file tools*
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
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: 19790
    
  20

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: 14435
    
  23

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 8 API documentation
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: converting string datetime object to date object.