Modifying timezone of a POSIXct object without changing the display

后端 未结 3 438
无人及你
无人及你 2021-02-01 23:45

I have a POSIXct object and would like to change it\'s tz attribute WITHOUT R to interpret it (interpret it would mean to change how the datetime is di

3条回答
  •  醉话见心
    2021-02-02 00:19

    To change the tz attribute of a POSIXct variable it is not best practice to convert to character or numeric and then back to POSIXct. Instead you could use the force_tz function of the lubridate package

    library(lubridate)
    
    datetime2 <- force_tz(datetime, tzone = "CET")
    datetime2
    attributes(datetime2)
    

提交回复
热议问题