Java TimeZone getAvailableIDs() Method



Description

The Java TimeZone getAvailableIDs() method is used to get all the available IDs supported.

Declaration

Following is the declaration for java.util.TimeZone.getAvailableIDs() method.

public static String[] getAvailableIDs()

Parameters

NA

Return Value

The method call returns an array of IDs.

Exception

NA

Java TimeZone getAvailableIDs(int rawOffset) Method

Description

The getAvailableIDs(int rawOffset) method is used to get the available IDs according to the given time zone offset.

Declaration

Following is the declaration for java.util.TimeZone.getAvailableIDs() method.

public static String[] getAvailableIDs(int rawOffset)

Parameters

rawOffset − This is the given time zone GMT offset.

Return Value

The method call returns an array of IDs, where the time zone for that ID has the specified GMT offset.

Exception

NA

Getting All Available IDs of TimeZones Example

The following example shows the usage of Java TimeZone getAvailableIDs() method to get the available time zoen ids. We've retrieved the available timezone ids using getAvailableIDs in form of String[] and then iterated them to print.

package com.tutorialspoint;

import java.util.TimeZone;

public class TimeZoneDemo {
   public static void main( String args[] ) {       

      // getting available Ids 
      String[] availId = TimeZone.getAvailableIDs();      
      
      // checking available Ids
      System.out.println("Available Ids are: ");

      for (int i = 0; i<availId.length; i++) {
         System.out.println(availId[i]);
      } 
   }    
}

Output

Let us compile and run the above program, this will produce the following result.

Available Ids are: 
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
...
VST

Getting All Available IDs of TimeZones with Given Offset Example

The following example shows the usage of Java TimeZone getAvailableIDs(int rawOffset) method to get the available time zoen ids according to the given time zone offset. We've retrieved the available timezone ids using getAvailableIDs in form of String[] and then iterated them to print.

package com.tutorialspoint;

import java.util.TimeZone;

public class TimeZoneDemo {
   public static void main( String args[] ) {       

      // getting available Ids 
      String[] availId = TimeZone.getAvailableIDs(3600000);      
      
      // checking available Ids
      System.out.println("Available Ids are: ");

      for (int i = 0; i<availId.length; i++) {
         System.out.println(availId[i]);
      } 
   }    
}

Output

Let us compile and run the above program, this will produce the following result.

Available Ids are: 
Africa/Algiers
Africa/Bangui
Africa/Brazzaville
...
Poland
java_util_timezone.htm
Advertisements