I am having a little bit of trouble with a time conversion between an android phone (Nexus one) and a java server. Everything I have read says that they are the same but when I am converting a long time stamp from i seem to lose 1 hour (exactly).
Specifically, If I run the following code on the android device I get the following output
Code:
Calendar g = Calendar.getInstance();
g.setTimeInMillis(1340661899000L);
Log.d(TAG, g.getTime().toLocaleString());
Output: Jun 25, 2012 6:04:59 PM
Which I think is correct, but when I run the exact same code on a java server I get a the same day but 1 hour earlier
Code:
Calendar g = Calendar.getInstance();
g.setTimeInMillis(1340661899000L);
System.out.println(g.getTime().toLocaleString());
Output: 25-Jun-2012 5:04:59 PM
Does anyone know what could be causing this? Both the server ad the phone are located in the same place (not that it should matter) and the clocks on both the server box and the phone match
Considering it's a difference of one hour, could you possible have DST (Daylight Savings Time) set on server and not on the phone or vice-versa?
What Chris is trying to say is that your phone and server may be configured to different timezones.
Try printing the result of cal.getTimeZone()
. should this be the issue you will want to pick a timezone to use for communications. For instance:
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+0"));
According to the JavaDocs the calendar instances use the default timezones reported by:
TimeZone.getDefault()
Despite your server and mobile being set to the same TimeZone may not necessarily mean they use the same default TimeZone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With