2012-08-11 56 views
5

我在xts對象中有一堆1分鐘的回報,索引是POSIXct,時區是GMT。回報在紐約證券交易所上市,所以我想轉換到東部時區,但我想妥善保管夏令時。這樣做的最好方法是什麼?我對EST時區和EDT時區有點混淆。我希望我的時代能夠在冬季和夏季正確地轉換到紐約時間。POSIXct和xts中的時區,從GMT轉換爲R

+0

「EST」 是東部標準時間和 「EDT」 是東部夏令時間。 – 2012-08-11 20:43:18

+0

那麼這是否意味着EDT包含夏令時更改,而EST不會呢?我只是不知道差異。 – Alex 2012-08-11 20:52:57

+0

他們是同一個時區。 「EDT」是DST生效時的情況。 – 2012-08-12 00:33:41

回答

5

使用indexTZ<-America/New_York時區

> tail(SPY) 
        SPY.Bid.Price SPY.Ask.Price SPY.Trade.Price SPY.Mid.Price SPY.Volume 
2012-08-09 19:54:00  140.47  140.48   140.48  140.475  2372 
2012-08-09 19:55:00  140.46  140.47   140.46  140.465  5836 
2012-08-09 19:56:00  140.47  140.48   140.48  140.475  2538 
2012-08-09 19:57:00  140.47  140.48   140.47  140.475  2209 
2012-08-09 19:58:00  140.48  140.49   140.49  140.485  4943 
2012-08-09 19:59:00  140.58  140.59   140.58  140.585  16780 
> indexTZ(SPY) <- "America/New_York" 
> tail(SPY) 
        SPY.Bid.Price SPY.Ask.Price SPY.Trade.Price SPY.Mid.Price SPY.Volume 
2012-08-09 15:54:00  140.47  140.48   140.48  140.475  2372 
2012-08-09 15:55:00  140.46  140.47   140.46  140.465  5836 
2012-08-09 15:56:00  140.47  140.48   140.48  140.475  2538 
2012-08-09 15:57:00  140.47  140.48   140.47  140.475  2209 
2012-08-09 15:58:00  140.48  140.49   140.49  140.485  4943 
2012-08-09 15:59:00  140.58  140.59   140.58  140.585  16780 
Warning message: 
timezone of object (America/New_York) is different than current timezone (GMT). 
+1

我可以問,你怎麼知道可以傳遞給'indexTZ'的可能值? – Alex 2012-08-11 21:20:19

+3

試試這兩頁的背景:http://en.wikipedia.org/wiki/Time_zone和http://en.wikipedia.org/wiki/IANA_time_zone_database – 2012-08-11 21:32:06

+0

或這一個:http://en.wikipedia.org/ wiki/List_of_tz_database_time_zones – GSee 2012-08-11 23:11:34