如何在R中转换Redis的日期 [英] How to convert Redis date in R
本文介绍了如何在R中转换Redis的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试转换这种日期:Tue Aug 12 2014 19:47:50 GMT + 0000(UTC)
I am trying to convert this kind of date: "Tue Aug 12 2014 19:47:50 GMT+0000 (UTC)"
parseRedisDate <- function(date) {
x <- gsub(" GMT\\+0000 \\(UTC\\)", "", date)
as.Date(x, format="%a %b %d %Y %T")
}
date <- "Tue Aug 12 2014 19:47:50 GMT+0000 (UTC)"
parseRedisDate(date)
不工作...
推荐答案
如果您需要完整的日期时间,您可以轻松地将该字符串强制为类 POSIXct
:
If you need the full datetime, you can easily coerce that string to an object of class POSIXct
:
x<-"Tue Aug 12 2014 19:47:50 GMT+0000 (UTC)"
as.POSIXct(x,format="%a %b %d %Y %H:%M:%S")
如果您的区域设置未设置为了解英文月份和日期名称,则可能会失败。您可以通过以下方式设置区域设置:
This may fail if your locale isn't set to understand the English month and day names. You can set the locale through:
Sys.setlocale(category="LC_TIME","C")
,上述命令将会工作。如果你只需要日期(没有时间),你可以强制 POSIXct
到 Date
:
and the above commands will work. If you just need the date (without the time), you can coerce the POSIXct
to Date
:
as.Date(as.POSIXct(x,format="%a %b %d %Y %H:%M:%S"))
这篇关于如何在R中转换Redis的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文