Change timezone in a POSIXct object Change timezone in a POSIXct object r r

Change timezone in a POSIXct object


It doesn't work with POSIXct because base::as.POSIXct.default simply returns x if it's already POSIXct. You can change the timezone via the tzone attribute:

attr(data$dateTime, "tzone") <- "Europe/Paris"


In the lubridate package there is a function with_tz which changes the timezone attribute (effectively what Joshua described).

dttm <- as.POSIXct("2016-01-01 10:10:10", tz = "UTC")dttm[1] "2016-01-01 10:10:10 UTC"

Change timezone from UTC to CET

with_tz(dttm, "CET")[1] "2016-01-01 11:10:10 CET"


As of 7/23/2021. indexTZ is deprecated. tzone is good to use.

tzone(data$dateTime) <- "Europe/Paris"