I an new to android and am having trouble working with jodatime. I am getting the same error as many people on here and I have tried all the suggestions but nothing is working for me. I am trying to display the variables a user selected from a date and time picker e.g. 'dayNow, monthNow' etc into one combined variable called 'timeselected' and set it to a textbox so then I can carry out a calculation in jodatime further on down.
The code is as follows:
DateTime dateTime = new DateTime(timeselected);
DateTimeFormatter fmt = DateTimeFormat.forPattern("dd MM yyyy" + "\n" + " h:mm a ");
String formattedtime = fmt.print(dateTime);
CalculateButton.setText(formattedtime);
// Plus some hours, minutes, and seconds to the original DateTime.
DateTimeFormatter fmt2 = DateTimeFormat.forPattern("dd MM yyyy" + "\n" + " h:mm a ");
DateTime dateTime1 = dateTime.plusHours(timeadded);
String endtimecalc = fmt2.print(dateTime1);
TextView endtime = (TextView) findViewById(endtimetextView);
endtime.setVisibility(View.VISIBLE);
endtime.setText(endtimecalc);
String timeselected = dayNow + "-" + monthNow + "-" + yearNow + " " + hourNow + ":" + minuteNow;
DateTime datetimselected = DateTime.parse(timeselected);
usertimeselection.setText((CharSequence) datetimselected.toDate());
}
});
FATAL EXCEPTION: main Process: com.almac.tracker, PID: 29114 java.lang.IllegalArgumentException: Invalid format: "2017-11-23 T 4:56" is malformed at " T 4:56" at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:945) at org.joda.time.DateTime.parse(DateTime.java:160) at org.joda.time.DateTime.parse(DateTime.java:149) at com.almac.tracker.CreateLine$5.onClick(CreateLine.java:274) at android.view.View.performClick(View.java:6219) at android.view.View$PerformClick.run(View.java:24482) at android.os.Handler.handleCallback(Handler.java:769) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6540) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)