2017-04-10 76 views
0

我加入与NSDate的值的事件获取错误的日期,而从我的应用程序在iPhone应用程序提醒添加事件

“2017年4月25日15:00:00 +0000”

根据我的时区,它是2017-04-25 08:40 PM。

我从函数获取NSDate值。

NSString *strDateTime = @"Tuesday, 25 Apr 2017 08:30 PM"; 
NSDateFormatter *formatterLocal = [[NSDateFormatter alloc] init]; 
[formatterLocal setTimeZone:[NSTimeZone systemTimeZone]]; 
[formatterLocal setDateFormat:@"EEEE, dd MMM yyyy hh:mm a"]; 
NSDate *dateAdd = [formatterLocal dateFromString:strDateTime]; 

虽然我检查提醒应用程序,它显示的日期是25/04/17,3:00 PM。虽然应该是25/04/17,晚上8:00。

任何人都可以请帮我从这!

我已经检查Get wrong time when adding an event to default calendar in iPhone

回答

0

我正好赶上我的错误。

我在“dueDateComponents”中设置了错误的时区。

以下是我的代码。

EKReminder *reminder = [EKReminder reminderWithEventStore:self.eventStore]; 
reminder.dueDateComponents = [self dateComponentsForDefaultDueDate]; 

- (NSDateComponents *)dateComponentsForDefaultDueDate { 
    /* 
    Changing date components 
    */ 
    NSCalendar *cal = [NSCalendar currentCalendar]; 
    //[cal setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]]; 
    NSDateComponents *components = [cal components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear |NSCalendarUnitHour | NSCalendarUnitMinute fromDate:[NSDate dateWithTimeIntervalSince1970:[_dictData[@"start"] longLongValue]]]; 

    components.hour = [components hour]; 
    components.minute = [components minute]; 

    return components; 
} 

我只是评论

// [CAL setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@ “GMT”]];

愚蠢的错误:p

相关问题