Reputation: 726
How do I convert the below character string to datetime in RStudio?
2018-02-01T12:40:04
Upvotes: 0
Views: 35
Reputation: 887851
We can keep the T
also in the format
as.POSIXct(str1, format = "%Y-%m-%dT%H:%M:%S")
#[1] "2018-02-01 12:40:04 EST"
Or use ymd_hms
from lubridate
library(lubridate)
ymd_hms(str1)
Or use anytime
library(anytime)
anytime(str1)
#[1] "2018-02-01 12:40:04 EST"
str1 <- "2018-02-01T12:40:04"
Upvotes: 4