我试着从日期时间列中用strftime提取日期和小时,但我不明白为什么返回的值比应该返回的值早1小时。例如,对于2013-01-01 00:00:00的日期时间,返回的值应该是2013-01-01 00,但我得到的是2012-12-31 23。我还尝试添加1小时,然后再提取,但在一长串日期上,这又扰乱了输出。请参考以下示例代码。
## creating the sequence of time steps for cleaned
start <- as.POSIXct('2013-01-01 00:00:00',tz='EST')
end <- as.POSIXct('2016-06-06 23:00:00',tz='EST')
timesteps = data.frame( seq.POSIXt(from = start, to =end , by = "5 min"))
colnames(timesteps) = "Time Index"
dateandhour = function (timeindex){
return(strftime(timeindex, format = "%Y-%m-%d %H"))
}
timesteps ['Date and Hour'] = sapply(timesteps$`Time Index`, dateandhour)
请告诉我这里我缺少了什么。非常感谢。