How can I get the time for scanresult.timestamp in EPOCH time? It looks like it is returning SystemClock.elapsedRealtimeNanos().
Asked
Active
Viewed 1,511 times
2 Answers
4
scanResultTimestampInMillisSinceEpoch = System.currentTimeMillis() - SystemClock.elapsedRealtime() + (scanResult.timestamp / 1000)

NeilS
- 625
- 7
- 13
-
I found I had to use the following: `long rxTimestampMillis = System.currentTimeMillis() - SystemClock.elapsedRealtime() + scanResult.getTimestampNanos() / 1000000;` – Glenn Dec 03 '15 at 05:26
-
It looks like the getTimestampNanos() method is for *bluetooth* scanresults, not wifi: http://developer.android.com/reference/android/bluetooth/le/ScanResult.html – REJH Apr 28 '16 at 07:30
-
@NeilS: why are you dividing the timestamp by 1000? It should already be milliseconds according to the docs..? NVM I read milliseconds but it says milliseconds ... :S – REJH Apr 28 '16 at 07:32
-
I use this to receive the timestamp of the wifi : `long actualTime = System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(SystemClock.elapsedRealtimeNanos() - scanning.timestamp, TimeUnit.NANOSECONDS);` However, I only received the scanning for one time. I'm still have difficulty for continuous WiFi scan – Reyha Nov 02 '21 at 02:28
0
What really worked for me was
long time = System.currentTimeMillis() -
(SystemClock.elapsedRealtime() - (scanResultTimestamp / 1000))

E.Akio
- 2,249
- 3
- 14
- 27