且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将日期时间字符串转换为R中的POSIXct日期/时间格式

更新时间:2022-11-19 09:49:49

您需要指定转换格式。阅读?strptime 以查看日期格式的所有选项。

You need to specify a format for your conversion. Take a read of ?strptime to see all of the options for date formats.

#YYYY-MM-DDT00:00:00.000-08:00
test <- "2013-12-25T04:32:16.500-08:00"
z <- as.POSIXct(test,format="%Y-%m-%dT%H:%M:%OS")
op <- options(digits.secs = 3)
z
#[1] "2013-12-25 04:32:16.5 EST"