0

Many questions about timezones in Android were already asked here on SO, however after going through all of them I still don't have the definitive answer why the following is happening:

Let's say I live in Germany, therefore have the preferred timezone offset +1. Then I decided to go to the US. While in the US, my device sends a message to the server with the timestamp local to where I am now in the US. I use the following code to get the timestamp:

 SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSSZ");
 fmt.setTimeZone(TimeZone.getDefault());
 String timeStamp = fmt.format(new Date());

the timestamp I get is for example: 2016-02-20 08:32:01.000769+01 while 08:32:01 is the right time at the place where I am at that moment, the offset is still +1, whereas it should be rather something like -6.

From the answers here on SO, I got the impression that the Android devices don't care about the current timezone (given by my current location) and still insist on the original preferred timezone.

So am I right the only way to get this correct is to query some server with my coordinates to get my current timezone?

How come the device automatically syncs with the current network time as I travel, but does not sync the timezone offset? The cell towers should know in which timezone offset they are operating.

NumberFour
  • 3,551
  • 8
  • 48
  • 72

1 Answers1

1

How come the device automatically syncs with the current network time as I travel, but does not sync the timezone offset? The cell towers should know in which timezone offset they are operating.

Yes they do and they usually provide this too. That's why you got related settings in your phone's "Date and Time" section. And this includes time zone as well. Yet, user must have this enabled and this value must be provided by towers which, again, usually works.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
  • So is there a way I can get that information the cell tower's providing? (if it is available) – NumberFour Feb 23 '16 at 09:21
  • Cannot tell for sure w/o research. Yet, Telephony Manager may be a good start + questions like [Retrieve cell towers information](http://stackoverflow.com/q/13294545/1235698). Android reads it so definitely it is readable. The question remains if this is available via public API or you need to be i.e. on rooted device to be more lucky – Marcin Orlowski Feb 23 '16 at 09:33
  • Ok. But given a device which doesn't have this readable via public API, my only option is to query some webservice to get the timezone I am *currently* in? – NumberFour Feb 23 '16 at 09:43
  • I do some research to see if there's no other options available. There are people who spent more time fighting with this so may provide more valuable hints. Yet, location/IP based solution does not look that bad at first glance though – Marcin Orlowski Feb 23 '16 at 10:06