当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java TimeZone Clone()用法及代码示例


TimeZone 类的 clone() 方法用于创建 TimeZone 类对象的副本。

用法

public Object clone()

返回

它返回 TimeZone 类对象的克隆

例子1

import java.util.*;
public class TimerTaskCloneExample1 {
   public static void main( String args[] ) {
      // here object is of the class TimerZone. 
      TimeZone obj = TimeZone.getDefault(); 
      System.out.println("ORIGINAL OBJECT OF TIMERZONE CLASS:" + obj);
      // here cloning is done of class TimerZone object.
      Object obj1 = obj.clone();      
      System.out.println("CLONE OBJECT OF TIMERZONE CLASS:" + obj1);
   }    
}

输出:

ORIGINAL OBJECT OF TIMERZONE CLASS:sun.util.calendar.ZoneInfo[id="Asia/Calcutta",offset=19800000,dstSavings=0,
useDaylight=false,transitions=7,lastRule=null]
CLONE OBJECT OF TIMERZONE CLASS:sun.util.calendar.ZoneInfo[id="Asia/Calcutta",offset=19800000,dstSavings=0,
useDaylight=false,transitions=7,lastRule=null]

例子2

import java.util.SimpleTimeZone;
public class TimerTaskCloneExample2{
    public static void main(String[] args) {
         // here object is of the class TimerZone. 
        SimpleTimeZone simpleTimeZone = new SimpleTimeZone(500, "INDIA");
        System.out.println("ORIGINAL OBJECT OF TIMERZONE CLASS:" + simpleTimeZone);
         // here cloning is done of class TimerZone object.
        Object cloneObject = simpleTimeZone.clone();
        System.out.println("CLONE OBJECT OF TIMERZONE CLASS:"+ cloneObject);
    }
}

输出:

ORIGINAL OBJECT OF TIMERZONE CLASS:java.util.SimpleTimeZone[id=INDIA,offset=500,dstSavings=3600000,
useDaylight=false,startYear=0,startMode=0,startMonth=0,startDay=0,startDayOfWeek=0,startTime=0,startTimeMode=0,
endMode=0,endMonth=0,endDay=0,endDayOfWeek=0,endTime=0,endTimeMode=0]
CLONE OBJECT OF TIMERZONE CLASS:java.util.SimpleTimeZone[id=INDIA,offset=500,dstSavings=3600000,
useDaylight=false,startYear=0,startMode=0,startMonth=0,startDay=0,startDayOfWeek=0,startTime=0,startTimeMode=0,
endMode=0,endMonth=0,endDay=0,endDayOfWeek=0,endTime=0,endTimeMode=0]




相关用法


注:本文由纯净天空筛选整理自 Java TimeZone Clone() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。