I have the same problem as https://stackoverflow.com/questions/15575713/modifying-timezone-of-a-posixct-object-without-changing-the-display. However, I followed the accepted response but I don't get the desired result.
dt is a string ("2017-07-07 15.46.00"
). I need to change it to data-time format with CDT time zone ("2017-07-07 15:46:00 CDT"
). I can do it by lubridate::ymd_hms
and I get my desired result (lub.dt: "2017-07-07 15:46:00 CDT") but it is too slow for my dataset size. I converted dt using fasttime::fastPOSIXct
which is very fast but the function assumes the input is in 'GMT'. So I used 'GMT' for the output as well to get the same date-time display (fast.dt: "2017-07-07 15:46:00 GMT"
). Finally, I tried to change the time zone by as.POSIXct. I used the same tz (America/Chicago) for origin and the function but I get this result "2017-07-07 16:46:00 CDT" which is (time +1).
library(lubridate)
library(fasttime)
dt <- "2017-07-07 15.46.00"
lub.dt <- ymd_hms(dt, tz = 'America/Chicago')
fast.dt <- fastPOSIXct(dt, tz = 'GMT')
fast.dt.new.tz <- as.POSIXct(x = as.numeric(fast.dt), origin = as.POSIXct("1970-01-01", tz = 'America/Chicago'),tz = 'America/Chicago')
Can anyone guide me what I did wrong?