在 Java 中建立 TimeZone 物件的副本


為了獲取 Java 中 TimeZone 物件的副本,我們使用 clone() 方法。clone() 方法建立一個 TimeZone 的副本。

宣告 - java.util.TimeZone.clone() 方法宣告如下 -

public Object clone()

我們來看一個 Java 程式,它使用 clone() 方法建立 TimeZone 物件副本 -

示例

 即時演示

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: 
" + obj);       // copying the TimeZone object       Object copy = obj.clone();       System.out.println("Copied object:
" + copy);    } }

輸出

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]

更新於: 26-6-2020

66 次瀏覽

職業生涯開始

完成課程後取得認證

開始
廣告
© . All rights reserved.