Java TimeZone getID() Method



Description

The Java TimeZone getID() method is used to get the ID of this time zone.

Declaration

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

public String getID()

Parameters

NA

Return Value

The method call returns the ID of this time zone.

Exception

NA

Getting ID of Timezone of Europe Region Example

The following example shows the usage of Java TimeZone getID() method to get the timezone Id of this object. We've created a TimeZone using Europe/Paris then printed the 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());
   }    
}

Output

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

ID value is :Europe/Paris

Getting ID of Timezone of Poland Region Example

The following example shows the usage of Java TimeZone getID() method to get the timezone Id of this object. We've created a TimeZone using Poland then printed the 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());
   }    
}

Output

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

ID value is :Poland

Getting ID of Timezone of India Region Example

The following example shows the usage of Java TimeZone getID() method to get the timezone Id of this object. We've created a TimeZone using India then printed the 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());
   }    
}

Output

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

ID value is :GMT
java_util_timezone.htm
Advertisements