0

I want to convert a String containing a date to Timestamp.

My String is something like this: 2014-06-10T03:03

What I try to do:

Date startDate = null, endDate = null;

    try {
        startDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").parse(fromDate);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    try {
        endDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")
                .parse(toDate);
    } catch (ParseException e) {
        e.printStackTrace();
    }

But I get this error:

java.text.ParseException: Unparseable date: "2014-06-10T03:03". 

1 Answer 1

2

Since you do not have the seconds in your DateString("2014-06-10T03:03"), you need to remove the pattern for seconds (":ss") from the format as well.

 startDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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