我创建的数据集的日期从2010-01-01到2010-08-1,间隔为5分钟。
library(chron)
t1 <- chron("2010/01/01","00:00:00",format=c("y/m/d","h:m:s"))
t2 <- chron("2018/01/01","00:00:01",format=c("y/m/d","h:m:s"))
deltat <- times("00:05:00")
date <- seq(t1,t2,by=times("00:05:00"))
我使用parsedate
包格式化日期以遵循ISO 8601标准。
library(parsedate)
date1 <- format_iso_8601(date)
head(date1)
[1] "2010-01-01T00:00:00+00:00" "2010-01-01T00:05:00+00:00"
[3] "2010-01-01T00:10:00+00:00" "2010-01-01T00:15:00+00:00"
[5] "2010-01-01T00:20:00+00:00" "2010-01-01T00:25:00+00:00"
默认使用GMT时区,但是,我想使用EET时区。 我明白了:
date1 <- as.POSIXct(date)
date2 <- format(date1,tz="Europe/Istanbul",usetz=TRUE)
[1] "2010-01-01 02:00:00 EET" "2010-01-01 02:05:00 EET"
[3] "2010-01-01 02:10:00 EET" "2010-01-01 02:15:00 EET"
[5] "2010-01-01 02:20:00 EET" "2010-01-01 02:25:00 EET"
这样,我得到了正确的时区。有没有办法可以让我的日期像2010-01-01 02:00:00+02:00
一样呈现?我该如何更改代码才能实现这一目标?
答案 0 :(得分:0)
format_iso_8601(as.POSIXlt(date,tz="EET"))
[1] "2010-01-01T02:00:00+00:00" "2010-01-01T02:05:00+00:00" "2010-01-01T02:10:00+00:00"
[4] "2010-01-01T02:15:00+00:00" "2010-01-01T02:20:00+00:00" "2010-01-01T02:25:00+00:00"