NSDateFormatter 在格式化时添加 11 分钟额外时间

发布于 2024-12-19 00:09:08 字数 983 浏览 4 评论 0原文

当我使用NSDateFormatter转换它们时,我似乎在我想要的日期值中添加+11分钟。

startDateendDate 作为 MyObject 上的 NSDate,打印到控制台:

START DATE: 2011-11- 28 18:00:00 +0000

结束日期: 2011-11-28 20:00:00 +0000


我的NSDateFormatter

NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];

[formatter setDateFormat:@"hh:MM a"];
[formatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];

设置dateRangeString

NSString *dateRangeString = [NSString stringWithFormat:@"%@ - %@", 
                                 [formatter stringFromDate:self.startDate],
                                 [formatter stringFromDate:self.endDate]];

错误结果dateRangeString

日期范围:18:11 PM - 20:11 PM

为什么时间要多加 11 分钟?我在转换过程中做错了什么?我是不是忘记了一些愚蠢的事情?所以,请帮助我保持理智!

I seem to be adding +11 minutes to my desired date values when I am converting them using NSDateFormatter.

The startDate and endDate as NSDates on MyObject, printed to the console:

START DATE: 2011-11-28 18:00:00 +0000

END DATE: 2011-11-28 20:00:00 +0000


My NSDateFormatter:

NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];

[formatter setDateFormat:@"hh:MM a"];
[formatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];

Setting the dateRangeString:

NSString *dateRangeString = [NSString stringWithFormat:@"%@ - %@", 
                                 [formatter stringFromDate:self.startDate],
                                 [formatter stringFromDate:self.endDate]];

The wrong resulting dateRangeString:

Date Range: 18:11 PM - 20:11 PM

Why is it adding an extra 11 minutes to the times? What am I doing incorrect in my conversion? Am I forgetting something silly? SO, please help my sanity!

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

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

发布评论

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

评论(2

靑春怀旧 2024-12-26 00:09:08

因为现在是十一月,也就是第十一个月。

Because it's November, the 11th month.

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