0

I am trying to get the timezone from native calendar using the following code but i am getting the timezone has Asia/Calcutta instead of just 'IST'

Calendar calendarLocal = Calendar.getInstance();
                // fetches time zone
                TimeZone timeZone = calendarLocal.getTimeZone();
                System.out.println("Time Zone getAvailableIDs() --->"+timeZone.getAvailableIDs());
               String[] x=timeZone.getAvailableIDs();
               for(int i=0;i<x.length;i++){
                    System.out.println("Time Zone IDs-->"+x[i]);
                 } 
                  System.out.println("Time Zone ID--->"+timeZone.getID());
                System.out.println(" Calender Default-------->>>"+timeZone.getDefault());
                System.out.println("Time Zone --->"+timeZone.getTimeZone(timeZone.getID()));

Here TimeZone is Asia/Calcutta i need it to print IST

user1195292
  • 233
  • 1
  • 3
  • 13

1 Answers1

0

BlackBerry Java doesn't give you the time zone short codes, at least not reliably (it only gaurantees to know about the "GMT" code). You can see my answer here for information about how to code a mapping between strings like "Asia/Calcutta" and "IST". (my method mapTimeZoneCodes() in that example)

I provide a template method for setting up the mapping, and a link to this article on Desktop Java, which seems to have a pretty complete list of the time zone codes, and how to map codes to the long Java time zone strings.

It will be boring work to copy the strings into my template, but once you have it, you'll be able to easily lookup the short code based on the long name:

String longName = timeZone.toString();
String shortCode = (String)_timeZones.get(longName);
Community
  • 1
  • 1
Nate
  • 31,017
  • 13
  • 83
  • 207