I’ve got 2 time values 1unit == 1sec (derived from timestamps) e.g 1308598131 that client thinks the time is and 1308594548 that the server thinks the time is – these have a difference of 3583.
In the real world the server timezone is 1 hour behind the client. I’m looking for some simple code (java pref as working on android but I could translate other languages if needed 🙂 ) to calculate the “real” diff which in this case is -14 e.g client is 14 secs behind server.
It needs to work if the servers are on same timezone or client is 1 hour ahead of server (it would be nice if it coped with more than 1 hour but at the moment I don’t envisage anyone outside the UK playing the game 🙂
regards
Simon
The answer is to get my client to convert its local time to UTC (which the server is on) – my code to do this is ended up like this-
android.text.format.DateFormat df = new android.text.format.DateFormat();
long scTM = System.currentTimeMillis();
scTM = scTM - TimeZone.getDefault().getOffset(scTM);
String launchTime = DateFormat.format("yyyyMMddkkmmss", scTM).toString();
Are the client and server returning their respective local times? If possible, can you have them return their UTC times and then you are dealing apples-to-apples and do not need to worry about time zones, daylight savings time, etc. as far as the difference goes?