NSDateFormatter 在格式化时添加 11 分钟额外时间
当我使用NSDateFormatter
转换它们时,我似乎在我想要的日期值中添加+11分钟。
startDate
和 endDate
作为 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 NSDate
s 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
MM
是几个月。
将 NSDate 格式化为年、月的特定样式、日、时、分、秒
MM
is for months.
Formatting NSDate into particular styles for both year, month, day, and hour, minute, seconds
因为现在是十一月,也就是第十一个月。
Because it's November, the 11th month.