ios NSDateComponents和2个特定的不同日期返回当天的组件

时间:2012-08-13 10:01:12

标签: ios date nsdatecomponents days

这是一个给我带来麻烦的代码序列:

NSLog(@"%@",date);
NSString *title = [NSString stringWithFormat:@"%2d", 
                   [[NSCalendar currentCalendar] components:CCCalendarUnits fromDate:date].day];
NSLog(@"%@ %@",title, [[NSCalendar currentCalendar] components:CCCalendarUnits fromDate:date]);

其中: #define CCCalendarUnits NSYearCalendarUnit | NSMonthCalendarUnit | NSWeekCalendarUnit | NSWeekdayCalendarUnit | NSDayCalendarUnit

2个日志:       日期: 2012-10-27 21:00:00 +0000

2012-08-13 12:44:14.298 xxx[2561:207] 2012-10-27 21:00:00 +0000
2012-08-13 12:44:14.299 xxx[2561:207] 28 <NSDateComponents: 0x842fe00>
    Calendar Year: 2012
    Month: 10
    Day: 28
    Week (obsolescent): 44
    Weekday: 1

日期: 2012-10-28 21:00:00

2012-08-13 12:44:14.299 365Quotes[2561:207] 2012-10-28 21:00:00 +0000
2012-08-13 12:44:14.300 365Quotes[2561:207] 28 <NSDateComponents: 0x82264a0>
        Calendar Year: 2012
        Month: 10
        Day: 28
        Week (obsolescent): 44
        Weekday: 1

您可以注意到,对于这两个日期(2012-10-27 21:00:00 +0000和2012-10-28 21:00:00 +0000),日组件是相同的(28)? 任何帮助,以弄清楚为什么会发生这种情况?

由于

0 个答案:

没有答案