I have a simple code, I record the time when the user hits a button and subtract that time from the current time. It should give me the difference.
The funny part is that if I print my vars they are correct but when I make the subtraction the result is the year 1969 the time the system takes as reference.
This is my code:
// I register this time to later compare to the current time.
startTime = System.currentTimeMillis().toDouble()
timer = Timer()
timer.schedule(timerTask {
runOnUiThread {
advanceTimer()
}
}, 0, 60)
fun advanceTimer() {
//Total time since timer started, in seconds
val currentTime = System.currentTimeMillis().toDouble()
time = currentTime-startTime
}
This is what the console prints:
D/startTime: 2020:12:20:21:27:39:78
D/currentTime: 2020:12:20:21:29:49:21
D/time: 1969:12:31:18:02:09:42
Can somebody help me, please?