1

I am trying to edit a column of datetime values in R that are in POSIXlt format. I would like to add or subtract each row in this column by a scalar value of hours to change timezones.

so far my code looks like:

df$Time_LMT <- strptime(paste(df$Time_LMT), format = "%Y-%m-%dT%H:%M:%S", tz = "UTC") 

str(df$Time_LMT)

df$Time_LMT = as.POSIXlt(df$Time_LMT,tz="Asia/Bangkok")

In the above example, I am trying to convert from the timezone UTC to the "Asia/Bangkok" timezone, however, the datetime data in the time_LMT column is still the same as it was for the UTC time, any help is appreciated.

neilfws
  • 32,751
  • 5
  • 50
  • 63
  • Useful info here - https://stackoverflow.com/questions/30904851/how-do-you-change-the-timezone-of-sys-time/30905052 - it depends if you want to change the displayed time/timezone without changing the underlying time (seconds since 1970-01-01 UTC), or actually forcing the same time as shown in UTC to Asia/Bangkok. – thelatemail Feb 16 '21 at 23:18
  • It would be easier to help if you create a small reproducible example along with expected output. Read about [how to give a reproducible example](http://stackoverflow.com/questions/5963269). – Ronak Shah Feb 17 '21 at 07:35

1 Answers1

0

Try:

library(lubridate)
with_tz(df$Time_LMT, "Asia/Bangkok")
eastclintw00d
  • 2,250
  • 1
  • 9
  • 18