简体   繁体   中英

R quantmod: Timezone in xts object

I am using getSymbols function from quantmod library in R to download data from yahoo finance . Could anyone explain to me why the time zone of the returned xts data is UTC while yahoo page is showing JST? Please see code below and the highlighted part in the image.

> library(quantmod)
> dat=getSymbols("2975.T", adjust=F,auto.assign = FALSE,from="1900-01-01")
> tzone(dat)
[1] "UTC"

在此处输入图像描述

As mentioned in comments, a Date doesn't have a timezone, but you could use lubridate , which sets timezone for a Date to UTC :

lubridate::tz(Sys.Date())
[1] "UTC"

You could then use with_tz to convert back to JST :

lubridate::with_tz(index(dat),"Japan")
  [1] "2019-06-03 09:00:00 JST" "2019-06-04 09:00:00 JST" "2019-06-05 09:00:00 JST" "2019-06-06 09:00:00 JST"
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM