Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String to date conversion

 
sanjeev kumar mandal
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to convert the date string to date format but it showing exception.I am copying my code below which i have written for conversion of a string to date format.

=====code starts here====
String myDate="Thu Dec 27 11:08:58 IST 2007";
java.text.SimpleDateFormat targetDateFormat = new java.text.SimpleDateFormat("(D) (M) (DD) (hh:mm:ss) (yyyy)");

java.util.Date d2 = now1.parse(myDate);
System.out.println("==============" +d2);
====code ends here=======

=====exception is ====
java.text.ParseException: Unparseable date: "Thu Dec 27 11:08:58 IST 2007"
at java.text.DateFormat.parse(Unknown Source)
(TestDate.java:113)

=======

I need the same format for the date ie only data type should be changed i.e output date will be Thu Dec 27 11:08:58 IST 2007.
Please help me to solve this problem.

Regards
Sanjeev
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15495
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The input string "Thu Dec 27 11:08:58 IST 2007" doesn't match the format string "(D) (M) (DD) (hh:mm:ss) (yyyy)".

For example, there is a time zone "IST" in the input string that isn't in the format string. And why do you have all those () braces in the format string?

Carefully read the API documentation of class SimpleDateFormat, it explains exactly how you should write your format string.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic