Java Utility Library

Java TimeZone - setID() Method



The java.util.TimeZone.setID() method is used to set the time zone ID. This does not change any other data in the time zone object.

Syntax

public void setID(String ID)

Parameters

ID Specify the new time zone ID.

Return Value

void type.

Exception

NA

Example:

In the example below, the java.util.TimeZone.setID() method is used to set the new time zone ID.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating a TimeZone object
    TimeZone tz = TimeZone.getDefault();
   
    //printing the name and ID 
    System.out.print("Display name is: ");
    System.out.println(tz.getDisplayName());
    System.out.println("ID is: " + tz.getID());

    //set the new time zone ID
    tz.setID("IST");

    //printing the new name and ID 
    System.out.print("New Display name is: ");
    System.out.println(tz.getDisplayName());
    System.out.println("New ID is: " + tz.getID());
  }
}

The output of the above code will be:

Display name is: Coordinated Universal Time
ID is: Etc/UTC
New Display name is: India Standard Time
New ID is: IST

❮ Java.util - TimeZone