Java中的 TimeZone clone() 方法及示例
Java中TimeZone 类的clone()方法用于创建现有此 TimeZone 的相同副本。
句法:
time_zone.clone()
参数:该方法不带任何参数。
返回值:该方法返回TimeZone 的一个实例,它是该 TimeZone 的副本。
下面的程序说明了 TimeZone 的 clone() 方法的工作:
示例 1:
// Java code to illustrate clone() method
import java.util.*;
public class TimeZoneDemo {
public static void main(String args[])
{
// Creating an object of TimeZone class.
TimeZone time_zone
= TimeZone.getDefault();
System.out.println("Original TimeZone: "
+ time_zone);
System.out.println();
// Cloning and displaying the time zone
System.out.println("Cloned TimeZone: "
+ time_zone.clone());
}
}
Original TimeZone:
sun.util.calendar.ZoneInfo[id=”Etc/UTC”,offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]
Cloned TimeZone:
sun.util.calendar.ZoneInfo[id=”Etc/UTC”,offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]
示例 2:
// Java code to illustrate clone() method
import java.util.*;
public class TimeZoneDemo {
public static void main(String args[])
{
// creating Timezone object whose id is Europe/Berlin
TimeZone time_zone
= TimeZone.getTimeZone("Europe/Berlin");
System.out.println("Original TimeZone: "
+ time_zone);
System.out.println();
// Cloning and displaying the time zone
System.out.println("Cloned TimeZone: "
+ time_zone.clone());
}
}
Original TimeZone:
sun.util.calendar.ZoneInfo[id=”Europe/Berlin”,offset=3600000,dstSavings=3600000,useDaylight=true,transitions=143,lastRule=java.util.SimpleTimeZone[id=Europe/Berlin,offset=3600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]]
Cloned TimeZone:
sun.util.calendar.ZoneInfo[id=”Europe/Berlin”,offset=3600000,dstSavings=3600000,useDaylight=true,transitions=143,lastRule=java.util.SimpleTimeZone[id=Europe/Berlin,offset=3600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]]