Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Create a copy of a TimeZone object in Java
In order to get a copy of a TimeZone object in Java, we use the clone() method. The clone() method creates of a copy of the TimeZone.
Declaration −The java.util.TimeZone.clone() method is declared as follows −
public Object clone()
Let us see a Java program which creates a copy of the TimeZone object using the clone() method −
Example
import java.util.*;
public class Example {
public static void main( String args[] ) {
// creating object of TimeZone
TimeZone obj = TimeZone.getDefault();
System.out.println("Initial object: \n" + obj);
// copying the TimeZone object
Object copy = obj.clone();
System.out.println("Copied object: \n" + copy);
}
}
Output
Initial object: sun.util.calendar.ZoneInfo[id="Etc/UTC",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null] Copied object: sun.util.calendar.ZoneInfo[id="Etc/UTC",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]
Advertisements