我怎样才能找到 locationManager.getLastKnownLocation(...).getTime() 和现在之间的区别?

How can I find the difference between locationManager.getLastKnownLocation(...).getTime() and now?

我知道这更像是一道数学题,但我如何才能找到从 locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER).getTime() 到现在的时间? getTime returns 自 1970 年 1 月 1 日以来的毫秒数。

因为自 1970 年 1 月 1 日以来两次 return 毫秒,您只需从另一个中减去一个即可得到以毫秒为单位的差异。

这是一些伪代码:

a = getLastKnownLocation().getTime() // old
b = getTime()                        // now

c = b - a        // c is milliseconds since last known location (assuming b and a are numeric)
c / 1000         // seconds since last known location
c / (60*1000)    // minutes
c / (60*60*1000) // hours