📜  Java中的 TimeZone getAvailableIDs(int val_offset) 方法及示例

📅  最后修改于: 2022-05-13 01:55:17.822000             🧑  作者: Mango

Java中的 TimeZone getAvailableIDs(int val_offset) 方法及示例

Java中TimeZone 类getAvailableIDs(int val_offset )方法用于根据提供的偏移值获取 TimeZone 类中所有支持和可用的 ID 的列表。

句法:

参数:该方法接受一个I nteger类型的参数val_offset ,它指的是时区偏移值。

返回值:该方法返回所有可用 ID 的数组,其中该 ID的时区具有指定值。

下面的程序说明了 TimeZone 的 getAvailableIDs() 方法的工作:

示例 1:

// Java code to illustrate
// getAvailableIDs() method
  
import java.util.*;
  
public class TimeZone_Demo {
    public static void main(String args[])
    {
  
        // Storing all the available Ids
        String[] Id_array
            = TimeZone.getAvailableIDs(7200000);
  
        // Displaying all the available Ids
        System.out.println("All the available"
                           + " Ids are: ");
  
        for (int count = 0;
             count < Id_array.length;
             count++)
            System.out.println(Id_array[count]);
    }
}
输出:
All the available Ids are: 
ART
Africa/Blantyre
Africa/Bujumbura
Africa/Cairo
Africa/Gaborone
Africa/Harare
Africa/Johannesburg
Africa/Khartoum
Africa/Kigali
Africa/Lubumbashi
Africa/Lusaka
Africa/Maputo
Africa/Maseru
Africa/Mbabane
Africa/Tripoli
Africa/Windhoek
Asia/Amman
Asia/Beirut
Asia/Damascus
Asia/Famagusta
Asia/Gaza
Asia/Hebron
Asia/Jerusalem
Asia/Nicosia
Asia/Tel_Aviv
CAT
EET
Egypt
Etc/GMT-2
Europe/Athens
Europe/Bucharest
Europe/Chisinau
Europe/Helsinki
Europe/Kaliningrad
Europe/Kiev
Europe/Mariehamn
Europe/Nicosia
Europe/Riga
Europe/Sofia
Europe/Tallinn
Europe/Tiraspol
Europe/Uzhgorod
Europe/Vilnius
Europe/Zaporozhye
Israel
Libya

示例 2:

// Java code to illustrate
// getAvailableIDs() method
  
import java.util.*;
  
public class TimeZone_Demo {
    public static void main(String args[])
    {
  
        // Storing all the available Ids
        String[] Id_array
            = TimeZone.getAvailableIDs(36000000);
  
        // Displaying all the available Ids
        System.out.println("All the available"
                           + " Ids are: ");
  
        for (int count = 0;
             count < Id_array.length;
             count++)
            System.out.println(Id_array[count]);
    }
}
输出:
All the available Ids are: 
AET
Antarctica/DumontDUrville
Asia/Ust-Nera
Asia/Vladivostok
Australia/ACT
Australia/Brisbane
Australia/Canberra
Australia/Currie
Australia/Hobart
Australia/Lindeman
Australia/Melbourne
Australia/NSW
Australia/Queensland
Australia/Sydney
Australia/Tasmania
Australia/Victoria
Etc/GMT-10
Pacific/Chuuk
Pacific/Guam
Pacific/Port_Moresby
Pacific/Saipan
Pacific/Truk
Pacific/Yap

参考: https: Java/util/TimeZone.html#getAvailableIDs(int)