I want to calculate time difference in seconds between to time instants. For example, during execution of the program, I set the value of a variable and after some time I change it again. What was the time difference between the recent change of value from the previous value?
I want to calculate time difference in seconds between to time instants. For example,
Share
You can use
System.currentTimeMillis()to save the current time at one millisecond resolution.Just save the time whenever the first event occurs (better use a long var to hold that value)
and again when the 2nd event occurs. The difference divided by 1000 will give you time difference in seconds.