My app compares local device time against a UK based server time, the device time must always be within two minutes (give or take) of the server time.. We've recently gained new clients in different timezones, so this causes an issue, due to time difference... Should this be done server-side or could this be handled on device? If this could be handled on device, any ideas would be greatly appreciated.
Asked
Active
Viewed 54 times
0
-
do this logic from server side. handling different time zone from app side is very tedious job. – Hemant Parmar Apr 10 '19 at 09:05
-
@HemantParmar, I've looked into it briefly, and came to the same conclusion. I couldn't find an obvious way forward on Android.. Thanks for your advice. – flatwhite Apr 10 '19 at 09:07
-
Did you manage to come up with a solution? – KillerKode Apr 16 '19 at 10:41
1 Answers
0
Normally you would generate a UNIX timestamp, these are timezone independent and can be encoded into any timezone you want. If you generate one on your server and one on your device, then it's just a simple case of getting the device to send a request to the server (e.g. HTTP GET) with it's timestamp and the server will compare the difference.
See https://stackoverflow.com/a/23062640/1928362 for more info on timestamps. If you let us know what programming language you are using (on the server side), then perhaps we can mock up some code for it.
In Android you can generate a Unix timestamp by doing the following:
long unixTime = System.currentTimeMillis() / 1000;

KillerKode
- 957
- 1
- 12
- 31