shickey
shickey

Reputation: 41

Change string including "T07:57:00Z" to a datetime type?

I have a list of strings which take the following form: "2019-03-05T07:57:00Z" and I need to convert them to a Date data type so that I can do calculations with them, however I can't get R to recognize the "T07:57:00Z" as a time. The format itself doesn't matter as long as it is in a form where I can do calculations, does R have a way to handle this form of date?

Upvotes: 0

Views: 146

Answers (2)

thothal
thothal

Reputation: 20399

Or with base R

(res <- as.POSIXct("2019-03-05T07:57:00Z", format = "%Y-%m-%dT%H:%M:%SZ"))
# [1] "2019-03-05 07:57:00 CET"

Upvotes: 1

Sonny
Sonny

Reputation: 3183

Use lubridate for datetime use cases:

lubridate::ymd_hms("2019-03-05T07:57:00Z")
[1] "2019-03-05 07:57:00 UTC"

Upvotes: 1

Related Questions