2

I have checked this site and the web for a solution but with no result. I have been looking all over the web for a solution to my date format problem. I have a string that I want to convert into a date format as follows:

yyyyMMdd-HH:mm:ss.SSS

My code is:

String myTestString = "20111215-07:26:48.689";
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HH:mm:ss.SSS", Locale.ENGLISH);
Date d = null;
try{
    d = sdf.parse(myTestString);
    System.out.println(d);
}catch(ParseException pe){
   pe.printStackTrace();
}

But I get:

java.text.ParseException: Unparseable date: "Fri Dec 16 15:48:42 GMT 2011"
at java.text.DateFormat.parse(DateFormat.java:337)
at TestClass.main(TestClass.java:54)

Any ideas?

Adnan
  • 113
  • 1
  • 4
  • See http://stackoverflow.com/questions/2375222/java-simpledateformat-for-time-zone-with-a-colon-seperator – csl Dec 15 '11 at 18:06
  • 1
    As far as I can tell, the above code snippet cannot possibly give the above result. The unparsable string reported by the error just is not the string declared by your code. – Mike Nakis Dec 15 '11 at 18:12
  • Ok I have corrected the output. Please let me know. Thanks! – Adnan Dec 16 '11 at 15:50
  • I do not see any correction. If you were in fact using the string "20111215-07:26:48.689" then the error would be [Unparseable date: "20111215-07:26:48.689"]. But obviously, the string you are using is not "20111215-07:26:48.689"; it is "Fri Dec 16 15:48:42 GMT 2011" instead. That's what the other guys are also trying to tell you. – Mike Nakis Dec 16 '11 at 22:51

2 Answers2

2

this is just runnin fine. you may not be running the same code :

enter image description here

dku.rajkumar
  • 18,414
  • 7
  • 41
  • 58
  • java.text.ParseException: Unparseable date: "Fri Dec 16 15:48:42 GMT 2011" at java.text.DateFormat.parse(DateFormat.java:337) at TestClass.main(TestClass.java:54) – Adnan Dec 16 '11 at 15:49
1

i think the code you are executing is out of sync with the code you showed above. This string "Thu Dec 15 17:51:56 GMT 2011" is exactly the value passed into the parse() method, so something is messed up in your environment.

jtahlborn
  • 52,909
  • 5
  • 76
  • 118