Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

converting string datetime object to date object.

 
amarshi mohanty
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

How to convert string date_time object to Date object.


 
Varun Chopra
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
amarshi mohanty wrote:Hi,

How to convert string date_time object to Date object.



Look at java.text.DateFormat and parse method
 
Amit Vinod Dali
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20606
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amid, please UseCodeTags. Also, that code won't work. The pattern clearly does not match the provided string.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15437
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic