0

I have a long csv file with multiple columns. The first column is datetime with a timezone offset:

2015-05-29 02:05:00+02:00

I am trying to read it with read_csv in R and I would like it to be converted to:

2015-05-29 04:05:00

But instead, read_csv gives me:

2015-05-29 02:05:00

Is there a way to parse and format the datetime, such that it correctly adds the extra timezone hour? Note that the timezone changes in my file at different times of the year (Daylight Saving Time). So, it can be +02:00 or +01:00, for instance

Michel Mesquita
  • 743
  • 7
  • 17

1 Answers1

0

using %z in format od POSIXct will help. tz "" represents local time zone. change tz as required.

as.POSIXct("2015-05-29 02:05:00 +0200", format="%F %T %z",tz = "")
  • 1
    Do you know if it is possible to parse your format directly through `readr::read_csv`? For instance, through `col_types` and `col_datetime`? https://stackoverflow.com/a/49193886/436193 – Michel Mesquita Dec 09 '22 at 05:56