this is the screenshot of my application the Time in which is 00:57:18 and the timeout 14:14:21 should be automatically calculated the time difference and the result will show in Total travel hours (circled with red)
What do you think I need to change in my codings to make the output show properly in Total Hours Difference Thank you so much.
this is the code of mine.
FormTimeOut.java
String date_n = new SimpleDateFormat("MM/dd/yyyy",
Locale.getDefault()).format(new Date());
TextView date = (TextView) findViewById(R.id.editText_timei_timedate);
date.setText(date_n);
DisplayDateTime = (TextView) findViewById(R.id.editText_timei_out);
DisplayDateTimeStart = (TextView)
findViewById(R.id.editText_travel_start);
DisplayDateTimeTotal = (TextView)
findViewById(R.id.editText_travel_total);
BTN = (Button) findViewById(R.id.button1);
calander = Calendar.getInstance();
simpledateformat = new SimpleDateFormat("HH:mm:ss");
Date = simpledateformat.format(calander.getTime());
simpledateformat2 = new SimpleDateFormat("HH:mm:ss");
Date2 = simpledateformat2.format(calander.getTime());
BTN.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick (View v){
DisplayDateTime.setText(Date);
DisplayDateTimeStart.setText(Date2);
try {
Date oldDate = (java.util.Date)
simpledateformat2.parse(String.valueOf(simpledateformat));
Date currentDate = new Date();
long diff = currentDate.getTime() - oldDate.getTime();
long seconds = diff / 1000;
long minutes = seconds / 60;
long hours = minutes / 60;
if (oldDate.before(currentDate)) {
DisplayDateTimeTotal.setText("hours:" + hours + "minutes:" + minutes);
}
// Log.e("toyBornTime", "" + toyBornTime);
} catch (ParseException e) {
e.printStackTrace();
}
}
});