与DateTime偏移量混淆 [英] Confused by DateTime offsets
问题描述
我试图了解如何解释GMT偏移量,以便可以在R中使用日期时间对象。例如,假设我有一个类似 2011-04-04 10:45:00 GMT + 10的日期时间
第一季度:我应该将其作为格林威治时间并加上10个小时以获取当地时间吗?还是当地时间,我需要减去10个小时才能获得格林尼治标准时间?我一直都理解是后者。
Q2:为什么R似乎使用前一种解释?例如
foo<-as.POSIXct( 2011-04-04 10:45:00,tz = Etc / GMT + 10)
attr(foo, tzone)<- GMT
foo
[1] 2011-04-04 20:45:00 GMT
嗯?我预计 GMT时间为2011-04-04 00:45:00
编辑:更令人困惑!如果我使用国家/城市而不是GMT偏移量指定时区,则结果会有所不同。
foo<-as.POSIXct ( 2011-04-04 10:45:00,tz = Australia / Sydney)
foo
[1] 2011-04-04 10:45:00 EST
attr(foo, tzone)<- GMT
foo
[1] 2011-04-04 00:45:00 GMT
什么?啊!为什么??
格林尼治标准时间+10实际上表示从格林尼治标准时间开始使用POSIX样式符号减去 10小时。 / p>
来自: https://www.ietf .org / timezones / data / etcetera
#我们在区域名称和输出中使用POSIX样式的符号缩写
#,尽管这与许多人的预期相反。
#POSIX在格林威治以西有积极的迹象,但许多人期望
#在格林威治以东的积极迹象。例如,TZ ='Etc / GMT + 4'使用
#的缩写 GMT + 4,并且比UT
#落后4小时(即格林威治以西),即使许多人希望这样做至
#表示比UT提前4个小时(即格林威治以东)。
I'm trying to understand how to interpret GMT offsets so I can work with datetime objects in R. For example, suppose I have a datetime like "2011-04-04 10:45:00 GMT+10"
Q1: Should I read that as a Grenwich time and add 10 hours to get the local time? Or is it a local time and I need to subtract 10 hours to get GMT? I always understood it was the latter.
Q2: Why does R seem to use the former interpretation? For example
foo <- as.POSIXct("2011-04-04 10:45:00", tz="Etc/GMT+10")
attr(foo, "tzone") <- "GMT"
foo
[1] "2011-04-04 20:45:00 GMT"
Huh? I expected "2011-04-04 00:45:00 GMT"
Edit: More confusing still! The result is different if I specify a timezone using Country/City rather than a GMT offset.
foo <- as.POSIXct("2011-04-04 10:45:00", tz="Australia/Sydney")
foo
[1] "2011-04-04 10:45:00 EST"
attr(foo, "tzone") <- "GMT"
foo
[1] "2011-04-04 00:45:00 GMT"
What? Argh! Why??
GMT+10 actually means minus 10 hours from GMT using "POSIX Style Signs".
From: https://www.ietf.org/timezones/data/etcetera
# We use POSIX-style signs in the Zone names and the output abbreviations,
# even though this is the opposite of what many people expect.
# POSIX has positive signs west of Greenwich, but many people expect
# positive signs east of Greenwich. For example, TZ='Etc/GMT+4' uses
# the abbreviation "GMT+4" and corresponds to 4 hours behind UT
# (i.e. west of Greenwich) even though many people would expect it to
# mean 4 hours ahead of UT (i.e. east of Greenwich).
这篇关于与DateTime偏移量混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!