Monday, August 23, 2010

TimeZones and Timezone offsets in Blackberry and J2me

In J2me , a class called TimeZone is used to determine offset of timezone.

First get all the Ids by


tring ids[]= TimeZone.getAvailableIDs();
for(int i=0;i<0;i++){
    // will give you the  TimeZone offsets such as +5,-4 etc.
    TimeZone.getTimeZone(ids[i]).getRawOffset();
}

// will return the timeZone offset set in the device.
TimeZone.getDefault().getRawOffset();

TimeZone class is applicable for both Blackberry and J2ME


From Blackberry 4.6 a new class TimeZoneUtilities is intoduced.

Just use the following code to retrieve array of Timezones
     
String str[]=TimeZoneUtilities.getDisplayNames(0);


The above code will give the list of important places and their corresponding timezones where as TimeZone class willl give only TimeZones (without city name).

2 comments:

  1. Using the getRowOffset, how do you compensate for day-light-savings-time?
    Also, getRowOffset does not return -4 or +5 but rather the actual milliseconds that you then have to convert (no biggy but thought that it should be pointed out).

    ReplyDelete
  2. Daylight saving is not static i.e Daylight saving changes from year to year.In that case its better to get daylight from web services.


    TimeZone.getDefault().getRawOffset() will return the timezone rather than time in millis....

    ReplyDelete