When I execute this code in plain java and in android, I get different results:
System.out.println(new Date(1311940549187l).toString());
-
In plain java, I get this output:
Fri Jul 29 13:55:49 CEST 2011 -
In android, I get this output:
Fri Jul 29 11:55:49 GMT+00:00 2011
I understand it has something to do with the time zone. But I really need to get the same output. How can I generate a Date object based on a Long value, and get the same date in both environments ?
Edit: I already use SimpleDateFormat and the two datetimes have 2 hours offset. Please tell me how to get rid of the offset.
this is how I use the SimpleDateFormat: new SimpleDateFormat("MM-dd-yyyy HH:mm")
The date is the same in both environment, but toString() gives a different result because the two environments are configured with a different timezone.
To format a date for a specific timezone, use a SimpleDateFormat and set the timezone to a specific value (GMT for instance).
UPDATE: