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

后端 未结 4 2179
南旧
南旧 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 14:06

    First, convert the London time to a POSIXct object:

    pb.txt <- "2009-06-03 19:30"
    pb.date <- as.POSIXct(pb.txt, tz="Europe/London")
    

    Then use format to print the date in another time zone:

    > format(pb.date, tz="America/Los_Angeles",usetz=TRUE)
    [1] "2009-06-03 11:30:00 PDT"
    

    There are some tricks to finding the right time zone identifier to use. More details in this post at the Revolutions blog: Converting time zones in R: tips, tricks and pitfalls

提交回复
热议问题