How do you convert dates/times from one time zone to another in R?

后端 未结 4 2194
南旧
南旧 2020-11-27 13:27

If I have a date like this in London time: \"2009-06-03 19:30\", how can I convert it to the equivalent time in the US West Coast?

4条回答
  •  时光说笑
    2020-11-27 13:58

    Change the tzone attribute of a 'POSIXct' object:

    > pb.txt <- "2009-06-03 19:30"  
    > pb.date <- as.POSIXct(pb.txt, tz="Europe/London")  
    > attributes(pb.date)$tzone <- "America/Los_Angeles"  
    > pb.date  
    [1] "2009-06-03 11:30:00 PDT"
    

    Note that this is still a POSIXct object, tzone has changed, and correct offset has been applied:

    > attributes(pb.date)
    $class
    [1] "POSIXct" "POSIXt" 
    
    $tzone
    [1] "America/Los_Angeles"
    

提交回复
热议问题