08-25-2011 07:53 PM
How to get GMT based time zone offset?
SimpleDataFormat class supports 'z' and returns strings like "America/Chicago".
But, I would like to get the offset time from GMT.(Example GMT: -8:00)
Other platforms support 'Z' option which returns the offset.
08-26-2011 02:56 AM
08-26-2011 05:01 AM
It might be a bit more complicated than that because I don't believe rawOffset includes DST.
I don't think there is an easy way to do this, but I would love to be proved wrong.
If there is no easy way, then I would determine the difference as follows:
a) Create a Calendar using GMT
b) Create a Calendar using local time
c) set them both to the same time (note that this does have to be the date/time that you are planning to display. You can't set the current date/time and expect the difference to be the same because it might be DST now and NOT at the time you are going to display)
d) Extract the hours and minutes from the Calendar Object to determine the difference. This might be quite complicated because of the possible 'end cases', e.g., if you are +8 hours, then the hour 23 from the GMT Calendar will correspond top hour 7 from the local time and you don't want to interpret this as plus 16.
09-23-2011 05:00 AM
I found another answer at: Get time zone offsets with DST
The basic idea is to look at Calendar.getOffset(). The trick is that this method takes a lot of arguments, so first create a time "right now".
Code extract below:
Calendar rightnow =
int timezoneOffset = TimeZone.getDefault().getOffset(1, rightnow.get(Calendar.YEAR), rightnow.get(Calendar.MONTH), rightnow.get(Calendar.DAY_OF_MONTH), rightnow.get(Calendar.DAY_OF_WEEK), rightnow.get(Calendar.MILLISECOND));