如何在 R 中将日期/时间从一个时区转换为另一个时区? [英] How do you convert dates/times from one time zone to another in R?
本文介绍了如何在 R 中将日期/时间从一个时区转换为另一个时区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我在伦敦时间有这样一个日期:2009-06-03 19:30",我如何将其转换为美国西海岸的等效时间?
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?
推荐答案
首先,将伦敦时间转换为 POSIXct
对象:
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")
然后使用format
打印另一个时区的日期:
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"
有一些技巧可以找到要使用的正确时区标识符.Revolutions 博客上这篇文章的更多详细信息:在 R 中转换时区:提示,技巧和陷阱
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
这篇关于如何在 R 中将日期/时间从一个时区转换为另一个时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文