Location.getTime() returning a future time.

Posted by fiXedd on Stack Overflow See other posts from Stack Overflow or by fiXedd
Published on 2010-03-31T19:08:16Z Indexed on 2010/04/01 0:53 UTC
Read the original article Hit count: 835

Filed under:
|
|
|

The following code:

// get the last known location
Criteria c = new Criteria();
c.setAccuracy(Criteria.ACCURACY_FINE);
Location lastKnown = mLocationManager.getLastKnownLocation(mLocationManager.getBestProvider(c, true));

// compare times
long currentTime = System.currentTimeMillis();
long gpsTime     = lastKnown.getTime();
long age         = (currentTime - gpsTime) / 1000;

Gives me:

currentTime = 1270062152738
gpsTime     = 1270085378000
age         = -23225

If you'll notice, it's returning the last location fix's time as a time in the future. Why is this happening?

EDIT:

From Location.getTime() :

Returns the UTC time of this fix, in milliseconds since January 1, 1970.

From System.currentTimeMillis() :

Returns the current system time in milliseconds since January 1, 1970 00:00:00 UTC. This method shouldn't be used for measuring timeouts or other elapsed time measurements, as changing the system time can affect the results.

© Stack Overflow or respective owner

Related posts about android

Related posts about time