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);
1

1 Answer 1

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");
Sign up to request clarification or add additional context in comments.

1 Comment

@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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.