gpt4 book ai didi

iphone - 根据时区创建 NSDate 对象

转载 作者:行者123 更新时间:2023-12-03 20:53:54 25 4
gpt4 key购买 nike

我从我的应用程序中获得以下日期格式。

07/18/2011/04/45/EDT

我将其子串为“07/18/2011/04/45”和“EDT”。

使用以下代码我编写了一个日期。

   NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MM/dd/yyyy/HH/mm"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"EDT"]];

NSDate *currentServerDate = [dateFormatter dateFromString:formattedDateString];
NSLog(@"currentServerDate %@",currentServerDate);

但是,当我打印 NSDate (使用上面的格式化程序创建)时,它打印为“2011-07-18 14:15:00 +0530”,其中 +0530 是我的时区。我需要编写相对于 EDT 时区的时间。我该怎么做?

谢谢

最佳答案

我认为时区可能不是你想象的那样。尝试记录 timeZoneWithAbbreviation: 返回的时区看看它告诉你什么。另外,请查看我链接到的文档:

In general, you are discouraged from using abbreviations except for unique instances such as “UTC” or “GMT”. Time Zone abbreviations are not standardized and so a given abbreviation may have multiple meanings—for example, “EST” refers to Eastern Time in both the United States and Australia

关于iphone - 根据时区创建 NSDate 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6731573/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com