NSTimeZone secondsFromGMTForDate 中的错误?

Errors in NSTimeZone secondsFromGMTForDate?

我正在编写一个涉及人们出生时间的应用程序,我正在尝试使用 IOS 来获得准确的 GMT 偏移量。我得到的答案显然是错误的,我想知道其他人是否遇到过这些问题,或者是否有任何解决方法。

这是我用来计算偏移量的代码(第一行),以及显示我得到的内容的日志记录代码。

    ret.dateTime.offset = [tz secondsFromGMTForDate:date] / 3600.0;
    double dstOffset = [tz daylightSavingTimeOffsetForDate:date] / 3600.0;
    NSLog(@"Setting offset for %@ on %@, to %3.1f", ret.location.description, ret.dateTime.briefDateDescription, ret.dateTime.offset);
    NSLog (@"  (TZ Name = %@, date = %@, dstOffset = %3.1f)", tz.name, date, dstOffset);

这里是结果 - 普利茅斯和纽约是正确的,它们处于东部时间,DST 偏移对所有这些都是正确的,但 secondsFromGMTForDate 与明尼阿波利斯(中部时间)相差一小时,并且向亚特兰大(东部时间)的另一个方向关闭一个小时。

Setting offset for Minneapolis, MN on 3/26/70, to -5.0
  (TZ Name = America/Menominee, date = 1970-03-26 14:29:00 +0000, dstOffset = 0.0)
Setting offset for Plymouth, MA on 1/13/80, to -5.0
  (TZ Name = America/New_York, date = 1980-01-14 02:52:00 +0000, dstOffset = 0.0)
Setting offset for Atlanta, GA on 10/10/48, to -6.0
  (TZ Name = America/Kentucky/Monticello, date = 1948-10-10 13:07:00 +0000, dstOffset = 0.0)
Setting offset for New York, NY on 6/11/80, to -4.0
  (TZ Name = America/New_York, date = 1980-06-11 12:25:00 +0000, dstOffset = 1.0)

有线索吗?其他人在 70 年 3 月 26 日尝试明尼阿波利斯时会得到什么? America/Menominee 绝对是中央时间,DST 偏移量为 0,secondsFromGMTForDate 绝对应该是 -6 小时,而不是 -5。

这些都是正确的。与大多数操作系统一样,Apple 的时区系统基于 IANA time zone data。该数据包括历史信息和当前信息,因此即使时区规则可能发生变化,旧日期也能正确转换。

对于 America/Menominee,数据包括此注释:

# Dickinson, Gogebic, Iron, and Menominee Counties, Michigan,
# switched from EST to CST/CDT in 1973.

你的考试日期是1970年,那时候区不一样

America/Kentucky/Monticello 的评论包括:

# After prolonged debate, and despite continuing deep differences of opinion,
# Wayne County (central Kentucky) is switching from Central (-0600) to Eastern
# (-0500) time.  They won't "fall back" this year.  See Sara Shipley,
# The difference an hour makes, Nando Times (2000-08-29 15:33 -0400).

你这个时区的测试日期是 1948 年,看起来那个位置当时是中部时间。