0

I am pulling data from a sports API and I am receiving the following format for a startTime column that I need to work with:

> dput(mydf)
structure(list(id = 29019:29023, startTime = c("2015-10-07T23:00:00.000Z", 
"2015-10-08T00:00:00.000Z", "2015-10-08T02:00:00.000Z", "2015-10-08T02:30:00.000Z", 
"2015-10-08T23:00:00.000Z")), row.names = c(NA, 5L), class = "data.frame")

> mydf
     id                startTime
1 29019 2015-10-07T23:00:00.000Z
2 29020 2015-10-08T00:00:00.000Z
3 29021 2015-10-08T02:00:00.000Z
4 29022 2015-10-08T02:30:00.000Z
5 29023 2015-10-08T23:00:00.000Z

> class(mydf$startTime)
"character"

I need to (a) convert this into a date-time type (not sure which type is best, i know there are a few date-time types in R), and then (b) adjust the time by 5 or 8 hours, since the times showing are GMT and I'd like either ET or PT times.

Any help with how to do this is greatly apprecaited!

Edit: Apparently this is a part of ISO-8601 date representation.

Canovice
  • 9,012
  • 22
  • 93
  • 211

1 Answers1

0

We can use ymd_hms from lubridate which will pick the T part in the string

library(tidyverse)
mydf %>% 
   mutate(startTime = ymd_hms(startTime))

Or specify the string 'T' also in the format

as.POSIXct(mydf$startTime, format = '%Y-%m-%dT%H:%M:%S')
akrun
  • 874,273
  • 37
  • 540
  • 662