For some reason I always have the hardest time with getting timestamps to display correctly but anyway here is my problem.
I am pulling events from the Calendar Provider API and some events such as the US Holidays calendar events are in UTC so the timestamp is not what it should be on the device (unless the device is in that timezone of course).
I have a timestamp of this 1374105600000 which is 07/18/2013 00:00:00 UTC so july 18th at midnight UTC. What I want is the timestamp of july 18th at midnight local device time.
This is what I do
Calendar cal = Calendar.getInstance();
TimeZone tz = cal.getTimeZone();
cal.setTimeInMillis(time);
long offset = tz.getRawOffset(); //gives me -18000000 5hr difference since I am in EST which I think is actually wrong because it should be a 4hr difference now with DST
So if I add this to the UTC timestamp
long local = time+offset;
it gives me the incorrect time july 17th at 3:00PM
If I subtract the times
long local = time-offset;
I still get the wrong time, it gives me july 18th at 1:00AM but I dont think I should even be subtracting because that wont work for people in + timezone differences.
What am I doing wrong, why can I not get the correct offset to get the correct time?
I was also using this like as reference too Link