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

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

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

语法 :

public static String[] getAvailableIDs(int val_offset)

参数: 该方法需要一个整数类型的参数 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://docs.oracle.com/javase/7/docs/api/java/util/TimeZone.html#getAvailableIDs(int)

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程