I am saving current date in timestamp value in my firebase with below code
userValues.put("p_date", ServerValue.TIMESTAMP);
what I need to do is show a time difference between above saved value and current timestamp value, I have tried below code
//time ago
String starttime = book.getP_date().toString(); //getting saved timestamp from firebase
//current time
Long tsLong = System.currentTimeMillis()/1000;
String endtime = tsLong.toString();
long diffTime = Long.parseLong(endtime) - Long.parseLong(starttime);
String elapsedtime = new SimpleDateFormat("hh:mm:ss").format(Long.parseLong(String.valueOf(diffTime)));
tvTimeAgo.setText(elapsedtime+"ago");
it is giving a result like 07:59:56 ago
shown time difference is returning wrong result also what I need to have is 0h 5min 3s ago
how can I achieve this?