如何将夏令时的 NSString 转换为 NsDate

发布于 2024-09-16 15:26:20 字数 394 浏览 3 评论 0原文

我有一个像这样的 NSString @"2010-08-30T11:00:00-04:00" 。如何将其转换为 NSDate ?应该使用哪种 DateFormat ?我尝试了这个@“yyyy-MM-dd'T'HH:mm:ss-SSS”。但没有成功。请帮我。

  • 编辑

我发现 @"yyyy-MM-dd'T'HH:mm:ss-SSS" 在操作系统版本 3.1 中工作正常。但它没有进入 4.0 。这个 问题< /a> 也指出了类似的问题。请给出解决方案

I have an NSString like this @"2010-08-30T11:00:00-04:00" . How to convert this to an NSDate ? Which DateFormat should be used with it ? I tried this @"yyyy-MM-dd'T'HH:mm:ss-SSS" . But didn't worked. Please help me.

  • Edit

I found @"yyyy-MM-dd'T'HH:mm:ss-SSS" was working fine in OS version 3.1 . But its not getting in 4.0 .This question also pointing similar problem. Please give a solution

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

音盲 2024-09-23 15:26:23

[yourNSDateFormatterVariable setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];

[yourNSDateFormatterVariable setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];

南巷近海 2024-09-23 15:26:23

知道时区为 GMT - 4 小时不足以确定是否应应用夏令时。夏令时是根据地缘政治边界确定的。例如,赤道上方和下方的同一月份不适用夏令时。其他靠近赤道的国家很少使用夏令时。

因此,您需要获取指定的时区才能正确应用夏令时。

Knowing the timezone to be GMT - 4 hours is not enough to determine if daylight saving should be applied or not. Daylight saving is determined based on the geopolitical borders. For instance is daylight saving not applied in the same months above and below equator. Additional countries close to equator do seldom use daylight saving at all.

So, you need to get the named timezone in order to be able to apply daylight saving correctly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文