Java Utility Library

Java TimeZone - clone() Method



The java.util.TimeZone.clone() method is used to create a copy of this TimeZone.

Syntax

public Object clone()

Parameters

No parameter is required.

Return Value

Returns a clone of the given TimeZone.

Exception

NA

Example:

In the example below, the java.util.TimeZone.clone() method is used to create a clone of the given TimeZone.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating a TimeZone object
    TimeZone tz = TimeZone.getDefault();

    //printing the TimeZone object
    System.out.println("Original TimeZone Object:\n" + tz);
    
    //creating a clone of the TimeZone object
    Object tzclone = tz.clone();

    System.out.println();

    //printing the cloned TimeZone object
    System.out.println("Cloned TimeZone Object:\n" + tzclone);
  }
}

The output of the above code will be:

Original TimeZone Object:
sun.util.calendar.ZoneInfo[id="Etc/UTC",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]

Cloned TimeZone Object:
sun.util.calendar.ZoneInfo[id="Etc/UTC",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]

❮ Java.util - TimeZone