Java TimeZone - getID() Method
The java.util.TimeZone.getID() method is used to get the ID of this time zone.
Syntax
public String getID()
Parameters
No parameter is required.
Return Value
Returns the ID of this time zone.
Exception
NA
Example:
In the example below, the java.util.TimeZone.getID() method is used to get the ID of the given time zone.
import java.util.*; public class MyClass { public static void main(String[] args) { //creating a TimeZone object TimeZone tz = TimeZone.getDefault(); //get the name and ID of the TimeZone object Object tzname = tz.getDisplayName(); Object tzid = tz.getID(); //printing the name and ID System.out.println("Display name is: " + tzname); System.out.println("ID is: " + tzid); } }
The output of the above code will be:
Display name is: Coordinated Universal Time ID is: Etc/UTC
❮ Java.util - TimeZone