2017-01-18 37 views
2

我住在委內瑞拉過去10年我們面對2 GMT的變化。Java時區什麼是轉換意味着什麼?

此代碼是在Java 7中更新運行76

System.out.println(TimeZone.getTimeZone("America/Caracas")); 

其中在2016年,我們有結束打印

sun.util.calendar.ZoneInfo[id="America/Caracas",offset=-16200000,dstSavings=0,useDaylight=false,transitions=5,lastRule=null] 

這與最新的當然是JDK的Java 8更新121最新的變化。

sun.util.calendar.ZoneInfo[id="America/Caracas",offset=-14400000,dstSavings=0,useDaylight=false,transitions=6,lastRule=null] 

我很想知道什麼是轉換意味着文檔說的類似。

沒有夏令時轉換安排可以用自定義時區ID

但委內瑞拉沒有白天儲蓄的地方,我不知道什麼過渡這一特定情況下,裝置不意味着總喜歡GMT變化的指定在歷史上還是如此?

+0

總體而言,我們用「轉型」來形容當地的「牆壁上時時間「有不連續性。如果不連續性將時間向前或向後移動,或者由於夏令時或標準時間的改變,這並不重要。這只是採取某些行動來修改本地時鐘的一點。您可以在所有技術平臺和技術之外的時間內找到這個術語。 –

回答

3

ZoneInfo classtransitions場此評論:

此數組描述該時區的GMT偏移的過渡,包括原始偏移量的變化和夏令時間變化。長整數由四位字段組成。

雖然委內瑞拉沒有DST,但它的GMT偏移量確實有一些變化。使用Linux命令zdump -v America/Caracas,你會得到以下輸出:

America/Caracas -9223372036854775808 = NULL 
America/Caracas -9223372036854689408 = NULL 
America/Caracas Wed Jan 1 04:27:43 1890 UT = Tue Dec 31 23:59:59 1889 LMT isdst=0 gmtoff=-16064 
America/Caracas Wed Jan 1 04:27:44 1890 UT = Wed Jan 1 00:00:04 1890 CMT isdst=0 gmtoff=-16060 
America/Caracas Mon Feb 12 04:27:39 1912 UT = Sun Feb 11 23:59:59 1912 CMT isdst=0 gmtoff=-16060 
America/Caracas Mon Feb 12 04:27:40 1912 UT = Sun Feb 11 23:57:40 1912 VET isdst=0 gmtoff=-16200 
America/Caracas Fri Jan 1 04:29:59 1965 UT = Thu Dec 31 23:59:59 1964 VET isdst=0 gmtoff=-16200 
America/Caracas Fri Jan 1 04:30:00 1965 UT = Fri Jan 1 00:30:00 1965 VET isdst=0 gmtoff=-14400 
America/Caracas Sun Dec 9 06:59:59 2007 UT = Sun Dec 9 02:59:59 2007 VET isdst=0 gmtoff=-14400 
America/Caracas Sun Dec 9 07:00:00 2007 UT = Sun Dec 9 02:30:00 2007 VET isdst=0 gmtoff=-16200 
America/Caracas Sun May 1 06:59:59 2016 UT = Sun May 1 02:29:59 2016 VET isdst=0 gmtoff=-16200 
America/Caracas Sun May 1 07:00:00 2016 UT = Sun May 1 03:00:00 2016 VET isdst=0 gmtoff=-14400 
America/Caracas 9223372036854689407 = NULL 
America/Caracas 9223372036854775807 = NULL 

觀察右邊的gmtoff列。每對線代表一個轉換。你可以看到十多年前有更多的轉換。

Java實際上有點不同。它只記錄自1900年以來的轉換,因此不包括1890年的偏移量。但它在未來增加了一個虛擬過渡。你可以看到下面的代碼的實際轉換(Java 8):

import java.lang.reflect.Field; 
import java.time.Instant; 
import java.util.TimeZone; 

public class SimpleTest { 

    public static void main(String[] args) { 
     TimeZone tz = TimeZone.getTimeZone("America/Caracas"); 

     Field f = null; 
     try { 
      f = tz.getClass().getDeclaredField("transitions"); 
      f.setAccessible(true); 
      long[] transitions = (long[]) f.get(tz); 
      f = tz.getClass().getDeclaredField("offsets"); 
      f.setAccessible(true); 
      int[] offsets = (int[]) f.get(tz); 

      for (long transition : transitions) { 
       Instant transitionInstant = Instant.ofEpochMilli(transition >> 12); 
       int offset = offsets[(int)transition & 0xF]; 
       System.out.println(transitionInstant + " : " + offset); 
      } 
     } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

    } 
} 

輸出是:

1900-01-01T00:00:00Z : -16060000 
1912-02-12T04:27:40Z : -16200000 
1965-01-01T04:30:00Z : -14400000 
2007-12-09T07:00:00Z : -16200000 
2016-05-01T07:00:00Z : -14400000 
2037-01-01T04:00:00Z : -14400000 
+0

很棒,但這是什麼意思我的朋友。美國/加拉加斯太陽12月9日06:59:59 2007年UT =太陽12月9日02:59:59 2007 VET isdst = 0 gmtoff = -14400 美國/加拉加斯太陽12月9日07:00:00 2007年UT =太陽12月9日02 :30:00 2007 VET isdst = 0 gmtoff = -16200只需一秒鐘? – chiperortiz

+0

@chiperortiz在zdump輸出中,每對線代表一個轉換 - *之前的偏移*和*之後的偏移*,所以這是第二個的差異。 Java做的有點不同。我只包含zdump輸出,以顯示過去有更多轉換。 – RealSkeptic

1

轉換是一個數組,你只能得到它的lenght(在本例中6)

我引述:

此數組描述該時區的GMT偏移, 的轉變包括原始偏移更改和夏令時更改。一個長整數由一個 四位字段組成。最重要的52位 字段表示從格里高利 1970年1月1日00:00:00格林威治標準時間以毫秒爲單位的轉換時間。接下來的4位字段是保留的,並且 必須是0.接下來的4位字段是用於偏移[]的索引值,用於轉換時的夏令時量。如果此值爲零,則表示 表示沒有夏令時,而不是索引值爲零。最少的 重要的4位字段是用於在轉換時偏移總偏移量GMT 偏移量[]的索引值。如果此時區沒有遵守日光節約時間 且從未更改過去的任何GMT偏移,則此 值爲空。

這裏的quelle