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)
Not working...
You don't want to use
date
as an object name, since that's a function in base R. But otherwise your function seems to work. The core bit of it:returns:
and
returns:
If you need the full datetime, you can easily coerce that string to an object of class
POSIXct
:This may fail if your locale isn't set to understand the English month and day names. You can set the locale through:
and the above commands will work. If you just need the date (without the time), you can coerce the
POSIXct
toDate
: