Java TimeZone getID() 方法



描述

Java TimeZone getID() 方法用於獲取此時區的 ID。

宣告

以下是 java.util.TimeZone.getID() 方法的宣告。

public String getID()

引數

返回值

方法呼叫返回此時區的 ID。

異常

獲取歐洲地區時區的 ID 示例

以下示例演示瞭如何使用 Java TimeZone getID() 方法獲取此物件的時區 ID。我們使用 Europe/Paris 建立了一個 TimeZone,然後列印了 ID。

package com.tutorialspoint;

import java.util.TimeZone;

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

      // create time zone object     
      TimeZone timezone = TimeZone.getTimeZone("Europe/Paris");

      // checking ID of this time zone         
      System.out.println("ID value is :" + timezone.getID());
   }    
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果。

ID value is :Europe/Paris

獲取波蘭地區時區的 ID 示例

以下示例演示瞭如何使用 Java TimeZone getID() 方法獲取此物件的時區 ID。我們使用波蘭建立了一個 TimeZone,然後列印了 ID。

package com.tutorialspoint;

import java.util.TimeZone;

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

      // create time zone object     
      TimeZone timezone = TimeZone.getTimeZone("Poland");

      // checking ID of this time zone         
      System.out.println("ID value is :" + timezone.getID());
   }    
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果。

ID value is :Poland

獲取印度地區時區的 ID 示例

以下示例演示瞭如何使用 Java TimeZone getID() 方法獲取此物件的時區 ID。我們使用印度建立了一個 TimeZone,然後列印了 ID。

package com.tutorialspoint;

import java.util.TimeZone;

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

      // create time zone object     
      TimeZone timezone = TimeZone.getTimeZone("India");

      // checking ID of this time zone         
      System.out.println("ID value is :" + timezone.getID());
   }    
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果。

ID value is :GMT
java_util_timezone.htm
廣告