To get the time I apply:

public String hhmmss(){ Locale locale = new Locale("ru", "RU"); SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss ", locale); String timevaluetime = timeFormat.format(new GregorianCalendar().getTimeInMillis()); return timevaluetime; 

At the moment1 I get the time String timevaluetime1 = hhmmss(); At time2 I get the time String timevaluetime2 = hhmmss() ; How to determine the difference in time (time period) elapsed between moment 1 and moment 2.

1 answer 1

Try not tested. I wrote a business case.

 mTextView.setText(getCalculatedTime()); public String getCalculatedTime(String timevaluetime1, String timevaluetime2 ){ SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss"); Date date1 = format.parse(timevaluetime1 ); Date date2 = format.parse(timevaluetime2 ); long difference = date2.getTime() - date1.getTime(); String str = String.valueOf(DurationFormatUtils.formatDuration(difference, "HH:mm:ss")); return str; } 
  • Does not pass: format.parse (timevaluetime1); and format.parse (timevaluetime2); underlined with a red wavy line, DurationFormatUtils is in red - Gosha
  • Take these two lines in Try / Catch - DevOma
  • LTD! Thank! And what can be done with the selection of the red DurationFormatUtils. - Gosha
  • Try this: DurationFormatUtils.formatDuration (difference, "HH: mm: ss", true) - DevOma
  • It did not work, but how to connect the class DurationFormatUtils or class Duration to the project? - Gosha