0
假設我們有這三個日期:更改在照顧DST的XTS時區(夏令時間)
original_dates<- c("2015-12-31T07:00:00", "2015-12-31T08:00:00", "2015-12-31T09:00:00")
這個載體:
vector<- c("a", "b", "c")
我們轉換日期POSIXct格式:
original_dates2<- as.POSIXct(original_dates, format="%Y-%m-%dT%H", tz = "GMT")
,並建立一個XTS:
my_xts<- xts(vector, order.by = original_dates2, frequency = "hourly")
所以我們有以下XTS對象:
> my_xts
[,1]
2015-12-31 07:00:00 "a"
2015-12-31 08:00:00 "b"
2015-12-31 09:00:00 "c"
Warning message:
timezone of object (GMT) is different than current timezone().
如果我想更改爲當地時間我會改變時區:
indexTZ(my_xts)<- "America/Los_Angeles"
,但是這會產生一個錯誤的結果,因爲我知道2015-12-31 07:00:00 GMT應該等於2015-12-31 00:00:00洛杉磯時間(即7小時。之前),不二零一五年十二月三十日23時00分00秒(即8小時。前)
> my_xts
[,1]
2015-12-30 23:00:00 "a"
2015-12-31 00:00:00 "b"
2015-12-31 01:00:00 "c"
Warning message:
timezone of object (America/Los_Angeles) is different than current timezone().
我想這是因爲該時區轉化indexTZ(my_xts)<- "America/Los_Angeles"
不考慮日光節約時間(DST),如圖所示由DST功能:
> dst(my_xts)
[1] FALSE FALSE FALSE
的問題是,我如何改變使得DST被照顧的時區?
更多細節:
> Sys.timezone()
[1] "Europe/Paris"
> R.version
_
platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
version.string R version 3.3.1 (2016-06-21)