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]]
相關用法
- Java TimeZone getRawOffset()用法及代碼示例
- Java TimeZone observesDaylightTime()用法及代碼示例
- Java TimeZone setID()用法及代碼示例
- Java TimeZone inDaylightTime()用法及代碼示例
- Java TimeZone setRawOffset()用法及代碼示例
- Java TimeZone setDefault()用法及代碼示例
- Java TimeZone getID()用法及代碼示例
- Java TimeZone hasSameRules()用法及代碼示例
- Java TimeZone getAvailableIDs()用法及代碼示例
- Java TimeZone getDefault()用法及代碼示例
- Java TimeZone getTimeZone()用法及代碼示例
- Java TimeZone getDisplayName()用法及代碼示例
- Java TimeZone getDSTSavings()用法及代碼示例
- Java TimeZone getOffset()用法及代碼示例
- Java TimeZone useDaylightTime()用法及代碼示例
注:本文由純淨天空篩選整理自Chinmoy Lenka大神的英文原創作品 TimeZone clone() Method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。