The data is in factor format "2018-01-02T20:40:40.000Z" and I want it to be in POSIXct format "2018-01-02 20:40:40". How do I achieve this ?
Asked
Active
Viewed 37 times
1 Answers
3
Check ?strptime
to know more about date-time formats
as.POSIXct(x, format = "%Y-%m-%dT%H:%M:%S")
#[1] "2018-01-02 20:40:40 GMT"
With lubridate
library(lubridate)
ymd_hms(x)
#[1] "2018-01-02 20:40:40 UTC"
Or with anytime
library(anytime)
anytime(x)
#[1] "2018-01-02 20:40:40 UTC"
data
x <- factor("2018-01-02T20:40:40.000Z")

Ronak Shah
- 377,200
- 20
- 156
- 213