这是 plist 或 Xcode 中的错误吗?
如果您在 Xcode 的 plist 编辑器或 Apple 的独立 plist 编辑器中创建日期项,
您会得到以下形式的内容
这是一个格式良好的 UTC ISO 日期(由“Z”表示)。因为当我将其读入我的应用程序时,我处于 UTC +10 时区。然后显示我晚上 8:30 出去,仍然很好。但是,如果这是我的时区中的时间,则应为
(将“Z”替换为我的时区偏移量)。我所有尝试将这些日期读入我的 iPhone 应用程序的操作都被拒绝,就好像它格式错误一样。在Apple编辑器中编辑具有此类日期的plist将“+10”更改为“Z”而不调整时间。
其他人是否认为我认为这是 plist 或 Xcode 中的错误是正确的?我的感觉是ISO日期和实施plist 中的时间不完整。
干杯,佩德罗:)
G'day All
If you create a date item in the plist editor of Xcode or Apple's standalone plist editor you get something of the form <date>2010-05-29T10:30:00Z</date>
which is a nice well formed ISO date at UTC (indicated by the "Z"). Because I'm in timezone UTC +10 when that's read into my app & then displayed I get 8:30 PM out, still good. However if that is a time in my timezone it should be <date>2010-05-29T10:30:00+10</date>
(replacing "Z" with my timezone offset). All of my attempts at reading such dates into my iPhone app have had the plist rejected as if it is malformed & editing a plist with such a date in Apple's editors changed the "+10" to "Z" without adjusting the time.
Do others think I'm correct in thinking this is a bug in either plist or Xcode? My feeling is that the implementation of ISO date & time in plist is incomplete.
Cheers, Pedro :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这都不是错误。在 CoreFoundation(和 Foundation)中,所有日期均以祖鲁时间表示,这就是它们以这种方式序列化的原因。然后,根据希望显示日期的设备的时区,对日期进行格式化以供显示。尽管这是一个 ISO 日期字符串,但 CoreFoundation/Foundation 的唯一有效时区是祖鲁时间。
如果出于某种原因,您需要跟踪生成任何给定日期的时区,则应将其作为单独的属性进行跟踪。如果您需要从其他地方编写 XML 属性列表,则必须首先将日期转换为 zulu,然后将其写出(尽管文档明确指定这些键仅用于调试辅助/可读性,并且将来可能会更改)。这使得 plist 成为在两个 Cocoa/CoreFoundation 应用程序之间序列化数据的一种不错的方式,但在 Cocoa/CoreFoundation 应用程序和其他应用程序之间序列化数据的方式不太合适。
It's not a bug in either. In CoreFoundation (and Foundation), all dates are represented in Zulu time, which is why they are serialized that way. The date is then formatted for display based on the timezone of the device that wishes to display it. Although this is an ISO date string, the only valid time zone for CoreFoundation/Foundation is Zulu time.
If, for some reason, you need to track the time zone that any given date was generated in, you should track this as a separate property. If you need to write an XML property list from somewhere else, you must first convert the date to zulu and then write it out (although the documentation clearly specifies that these keys are for debugging aids/readability only and may change in the future). This makes plists a decent way to serialize data between two Cocoa/CoreFoundation applications, but a less suitable way of serializing data between a Cocoa/CoreFoundation app and some other application.