英文:
Changing the time based on the time zone but R doesn't recognize CEST
问题
我有一个长时间列表(UTC),我希望将其转换为本地时间,这里是CEST。为此,我一直在使用with_tz("2023-02-05 08:50:00", tzone = "Europe/Madrid")
或with_tz("2023-02-05 08:50:00", tzone = "CET")
,但返回的时间比2023-02-05 09:50:00
提前1小时。然而,在夏令时月份,R没有识别到我们实际上是在CEST,返回的时间应该是2023-02-05 10:50:00
。我一直在使用OlsonNames()
来获取所有被识别的时区的列表,但似乎找不到CEST,有人有解决方法或替代方法吗?
英文:
I have a long list of times (UTC) which I wish to convert to local time, which in this instance is CEST. To do this I have been using with_tz("2023-02-05 08:50:00", tzone = "Europe/Madrid")
or 'with_tz("2023-02-05 08:50:00", tzone = "CET")' which returns a time 1 hour forward of 2023-02-05 09:50:00
however during the daylight savings months R doesn't recognize that we are in fact in CEST and the time being returned should be 2023-02-05 10:50:00
. Ihave been using 'OlsonNames()' to get a list of all the recognized timezones but cant seem to see CEST on there so does anyone have a fix or an alternative for this?
答案1
得分: 1
这似乎运行正常,并在适当的情况下识别CET与CEST:
t1 <- as.POSIXct("2023-05-22 11:11:11", format="%Y-%m-%d %H:%M:%OS", tz = "UTC")
t2 <- as.POSIXct("2023-02-22 11:11:11", format="%Y-%m-%d %H:%M:%OS", tz = "UTC")
lubridate::with_tz(c(t1, t2), tzone = 'Europe/Berlin')
[1] "2023-05-22 13:11:11 CEST" "2023-02-22 12:11:11 CET"
同样适用于以下情况:
lubridate::with_tz(c(t1, t2), tzone = 'Europe/Madrid')
[1] "2023-05-22 13:11:11 CEST" "2023-02-22 12:11:11 CET"
也许需要检查您的日期或代码?或者提供一个可重现的示例。
英文:
This seems to work fine and recognise the CET vs CEST where appropriate:
t1 <- as.POSIXct("2023-05-22 11:11:11", format="%Y-%m-%d %H:%M:%OS", tz = "UTC")
t2 <- as.POSIXct("2023-02-22 11:11:11", format="%Y-%m-%d %H:%M:%OS", tz = "UTC")
lubridate::with_tz(c(t1, t2), tzone = 'Europe/Berlin')
[1] "2023-05-22 13:11:11 CEST" "2023-02-22 12:11:11 CET"
also so does this:
lubridate::with_tz(c(t1, t2), tzone = 'Europe/Madrid')
[1] "2023-05-22 13:11:11 CEST" "2023-02-22 12:11:11 CET"
Perhaps check your dates or code? or give a reproducible example.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论