Converting character to timestamp in dataframe

旧街凉风 提交于 2019-12-01 22:46:53

We can use anytime

library(anytime)
anytime('2016-11-01T00:15:00.000Z')
#[1] "2016-11-01 00:15:00 IST"

Or use strptime

strptime('2016-11-01T00:15:00.000Z', '%Y-%m-%dT%H:%M:%OSZ')
#[1] "2016-11-01 00:15:00 IST"

Z means it's UTC time. So one option is just to strip out the letter and convert to POSIXCT with tz="UTC" . As the dataframe is not easily reproducible, I'm just using the vector of two dates:

x<- as.POSIXct( gsub(pattern = "[A-Z]",replacement = " ",
                 x = c( "2016-11-01T00:45:00.000Z","2016-11-01T00:39:00.000Z") ) ,
                 tz="UTC" ) 
x
class(x)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!