- Forum posts: 9
Sep 3, 2018, 9:30:06 PM via Website
Sep 3, 2018 9:30:06 PM via Website
I am quite new to Android development. I need to get the difference(duration) between two data/time values. When I try to get the difference between to date/times I guess the app is crashing. Heres the code:
// txtStartDate text = 4/8/2018
// txtStartTiem text = 11:16 PM
// txtEndDate text = 4/8/2018
// txtEndtime text = 12:30 (0:30 AM)
String format ="yyyy-MM-dd'T'HH:mm:ss" ;//“yyyy-MM-dd’T’HH:mm:ss”;
SimpleDateFormat simpleFormat = new SimpleDateFormat(format);
String strStartDateText = txtStartDate.getText().toString() + " " + txtStartTime.getText().toString();
Date startDate = simpleFormat.parse(strStartDateText , new ParsePosition(1));
String strEndDateText = txtEndDate.getText().toString() + " " + txtEndTime.getText().toString();
Date EndDate = simpleFormat.parse(strEndDateText , new ParsePosition(1));
long different = EndDate.getTime() - startDate.getTime(); // suspected crash.
What could be wrong here?
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.