0

I am pulling a date from a server in ISO 8601 format. The date represents the time a specific episode of a specific show airs. Here is an example date:

"2013-07-30T21:00:00-05:00"

That is July 30th, 2013 at 9:00PM EST. EST being -05:00. The problem comes in when I try and display the date back to the user(myself in this case). I am currently in central time but daylight savings time is active. Which means iOS says that I am currently in Central Daylight Time which is also -05:00(normal CST is -06:00).

This show airs in my CST time zone at 8:00PM. It doesn't matter if daylight savings time is on or off, the show always airs whenever the clock hits 8:00PM. Normally if I wasn't in daylight savings time iOS would be able to do the proper conversions as it would be moving from -05:00 to -06:00. SInce I am currently in daylight savings time though it sees -05:00 as the original offset and -05:00 as my current offset so it does no conversion and displays the show starting at 9:00PM. Any idea how to deal with this?

4

1 回答 1

0

不幸的是,没有办法将时区偏移-05:00映射回像中央时间或东部时间这样的实际时区正如您所指出的,它可能是中央夏令时间或东部标准时间。但是,可能是任何数量的其他时区碰巧-05:00在某一点或另一点使用了偏移量。请参阅此时区列表并按偏移列之一进行排序,以便您了解它们的数量。你也可以看这里

现在幸运的是,您还有另一条信息——日期/时间。因此,您可以使用它来部分区分其中一些区域。如果您确定您的数据是美国,您还可以进一步限制歧义。

不过还有一个问题。像这样的时间2013-11-03T01:00:00-05:00实际上同时在CDT 和 EST 中!这个怎么可能?好吧,在美国,我们不会同时改变我们的时钟。每个时区在他们自己的当地时间凌晨 2 点更改它。所以每年有一个小时东部时间已经经历了他们的后备过渡,但中央时间还没有。

处理所有这些的唯一真正方法是存储一些其他的上下文信息,例如完整的 IANA 时区(America/New_York东部或America/Chicago中部等) - 或者如果它只是为了显示,那么你可以存储一个字符串使用您选择的时区缩写(EST、CDT 等)。

另请参阅:时区标签 wiki 中的“时区!= 偏移量” 。

于 2013-09-07T18:35:55.947 回答