I see three ways to get millis (Kotlin)
val millis = Date().getTime() + (event.timestamp - System.nanoTime()) / 1000000L
val millis = System.currentTimeMillis() + (event.timestamp - System.nanoTime()) / 1000000L
val millis = System.currentTimeMillis() + (event.timestamp - SystemClock.elapsedRealtimeNanos()) / 1000000L
all three deliver same result, but when I want to see diff from calculated value to current time
val diff = System.currentTimeMillis() - millis
I see 'diff' with value -359704905 ?
Log.d("diff", "" + event.timestamp + " - " + System.nanoTime())
diff: 541695268300000 - 181990403666592
diff: 541695277240000 - 181990405818592
diff: 541695286859000 - 181990411901592
diff: 541695296139000 - 181990412584592
diff: 541695305735000 - 181990415222592
So all suggested solution are not right
for me this simple way fits my needs
override fun onSensorChanged(sensorEvent: SensorEvent?) {
val millis = System.currentTimeMillis()
}