SantiClaus
SantiClaus

Reputation: 726

How to convert a specific character string to datetime?

How do I convert the below character string to datetime in RStudio?

2018-02-01T12:40:04

Upvotes: 0

Views: 35

Answers (1)

akrun
akrun

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"

data

str1 <- "2018-02-01T12:40:04"

Upvotes: 4

Related Questions