rafik rafik -4 years ago 118
Java Question

String Convert to Joda DateTime

I have two strings a date and a time sample "20170609" and "122600".
I would now have to make these two such a format

"yyyy-MM-dd'T'HH: mm: ss.SSSZ"
.

I get this issue: Invalid format: "
124700 20170515" is malformed at " 20170515"
.

What am I doing wrong?

The method looks like this:

private DateTime StringToDateTime(String dateString, String timeString) {
String string = dateString+" "+timeString;
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
DateTime dt = formatter.parseDateTime(string);
return dt;
}

Answer Source

Your format does not fit to the expected Format. Change to:

DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyyMMdd HH:mm:ss");

because this is the Format of the concatibated Strings: 20170609 122600

Also it Looks like you call the method with twisted parameters 124700 20170515

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download