Comparing times and acting accordingly
So I have a scenario:
Using System.currentTimeMillis()
I get the initial start time of my application. Then, when I open it at another time, I get the time again. Both of these times are saved as a long
variable.
What I need to do is compare these two times, convert this difference to hours (x 600,000), and for every hour that has passed, subtract 5 from another integer variable. I can find the difference in time, convert it to hours, but I can't figure out to subtract 5 for every hour that has passed. Any help or p开发者_JAVA技巧seudo code would be GREATLY appreciated.
-Nathan
If for every hour we subtract 5, then after {x} hours we will have subtracted 5 * x
.
So work out how many hours have passed, multiply it by five, and there you go.
精彩评论