• Post Reply Bookmark Topic Watch Topic
  • New Topic

problem in Converting String to Date Object  RSS feed

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi i am getting Run time Exception while converting String object to Date Object can some one please Advise



java.text.SimpleDateFormat@b9b195a0
java.text.ParseException: Unparseable date: "14-07-2012"





public static void main(String[] args) {
String time = "14-07-2012";
DateFormat df = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
try {
Date date = df.parse(time);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(df);
}


 
Ranch Hand
Posts: 119
Hibernate Java Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is simply because your date string value doesn't clearly match with the date pattern of your target. Try to remove the time portion from the SimpleDateFormat. And please use the UseCodeTags to format your code.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!