0

I have a date as a String format like this -

String testDate = "2014-11-5T19:11:27";

Now I need to convert above String date to java.util.Date format. I was trying below code but it is not able to recognize T in it.

String testDate = "2014-11-5T19:11:27";
DateFormat formatter = new SimpleDateFormat("yyyy-MM-ddTHH:mm:ss");
Date date = formatter.parse(testDate);
System.out.println(date);
AKIWEB
  • 17,808
  • 64
  • 175
  • 282
  • possible duplicate of [How can I convert a timestamp from yyyy-MM-ddThh:mm:ss:SSSZ format to MM/dd/yyyy hh:mm:ss.SSS format? From ISO8601 to UTC](http://stackoverflow.com/questions/5393847/how-can-i-convert-a-timestamp-from-yyyy-mm-ddthhmmsssssz-format-to-mm-dd-yyyy) – Basil Bourque Nov 17 '14 at 00:11

1 Answers1

3

T needs to be enclosed in quotes since it isnt used to match a date element in the DateFormat pattern

DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Reimeus
  • 155,977
  • 14
  • 207
  • 269
  • @AKIWEB It's a standard used for timestamps that avoids having spaces in them, which in many programming context would indicate field separation. With `T` it's easier to parse text files that contain time stamps. – RealSkeptic Nov 16 '14 at 21:52