用R解析ISO8601日期和时间格式 [英] Parsing ISO8601 date and time format in R
本文介绍了用R解析ISO8601日期和时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这应该很快-我们正在R中解析以下格式:
This should be quick - we are parsing the following format in R:
2013-04-05T07:49:54-07:00
2013-04-05T07:49:54-07:00
我当前的方法是
require(stringr)
timenoT <- str_replace_all("2013-04-05T07:49:54-07:00", "T", " ")
timep <- strptime(timenoT, "%Y-%m-%d %H:%M:%S%z", tz="UTC")
,但给出的是 NA
。
推荐答案
%z
是小时的符号偏移量,格式为 hhmm
,而不是 hh:mm
。这是删除最后一个的一种方法:
。
%z
is the signed offset in hours, in the format hhmm
, not hh:mm
. Here's one way to remove the last :
.
newstring <- gsub("(.*).(..)$","\\1\\2","2013-04-05T07:49:54-07:00")
(timep <- strptime(newstring, "%Y-%m-%dT%H:%M:%S%z", tz="UTC"))
# [1] "2013-04-05 14:49:54 UTC"
还请注意,您不必删除 T
。
Also note that you don't have to remove the "T"
.
这篇关于用R解析ISO8601日期和时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文