Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate time between two times Android

Tags:

android

time

basically i have one time

currentTime = DateFormat.getTimeInstance().format(new Date());

and i want to calculate how much time has past since currentTime. any ideas?

like image 980
Simon Avatar asked Jul 28 '10 10:07

Simon


People also ask

How do I calculate hours between two times?

How many hours are between 9:00 and 17:00? There are 8 hours between 9:00 and 17:00. To calculate how many hours are between two times, you should subtract a start time from the end time.


1 Answers

Your currentTime as above will be a String, so difficult to work with.

If you use a Date object instead:

Date interestingDate = new Date();

then you can find the different in milliseconds between the actual current date and interestingDate by doing:

(new Date()).getTime() - interestingDate.getTime()

Also check out the Time class which you could use instead of the Date class.

like image 184
oli Avatar answered Oct 12 '22 14:10

oli