Luke B.
Luke B.

Reputation: 137

Getting wrong and very old timestamps from Location.getTime()

I started noticing a very strange behaviour in a tablet of mine, and it's not even consistent, some days I have it, some days I don't. I'll describe what happens when I have the problem.

In this (quite old) android application, gps locations are retrieved through this classic piece of code:

LocationManager locationManager = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 0, new LocationListener() {
@Override
public void onLocationChanged(Location location) {
---
}
}

When I get a new Location object, if I use getTime() on it, I'm getting a strange timestamp, like it was from almost 20 years ago. Today, 19th October 2022, I'm getting locations with timestamps like "1046871199999", which translates to 5th March 2003.
Six days ago, when I noticed the same problem, I was getting locations with timestamps like "1046360561000", which translates to 27th February 2003, exactly six days before. So it looks like it's always the same exact amount that is subtracted from the actual timestamps.

Meanwhile, System.currentTimeMillis() always works ok, and returns the correct timestamps.

I have this problem happening randomly on a Android 11 tablet, and doesn't stop doing it even after a reboot. I'm using the same application on a Android 7 tablet as well, and never got it on there.

Any clue on the cause? Thanks!

Upvotes: 1

Views: 190

Answers (0)

Related Questions