Universal time management (with T) when adding an event to the Xcode calendar

I am trying to find the answer everywhere, including StackOverflow .. I have a problem adding a temporary event from a line that looks like this: 2014-12-31T19: 00: 00-06: 00. By the way, I am parsing this from XML. The rest of the code, including shortcuts, etc., works fine.

So, here is my code for adding new events to the calendar (I tried to add 'dateFromString' already as a name with the current time to check, and it passes):

EKEventStore *store = [[EKEventStore alloc] init];
[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
    if (!granted) { return; }
    EKEvent *event = [EKEvent eventWithEventStore:store];
    event.title = tempNameOfEvent;
    event.startDate = dateFromString; //here is a NSDate but incorrectly formatted
    event.endDate = [event.startDate dateByAddingTimeInterval:60*60];  //set 1 hour meeting
    [event setCalendar:[store defaultCalendarForNewEvents]];
    NSError *err = nil;
    [store saveEvent:event span:EKSpanThisEvent commit:YES error:&err];
}];

Code from Programmatically Add Custom Event to iPhone Calendar

, NSDate EKEventStore? "yyyy-MMM-dd HH: mm: ss ZZZ", "2007-01-09 17:00:00 +0000"? "-06: 00"? ( XML : 2014-12-31T19: 00: 00-06: 00).

+4
2

, "", "" "".

: yyyy-MM-dd'T'HH: mm: ssxxx

: ICU
: .

:

NSString *ds = @"2014-12-31T19:00:00-06:00";
NSDateFormatter *df = [NSDateFormatter new];
[df setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssxxx"];
NSDate *d = [df dateFromString:ds];
NSLog(@"d: %@", d);

:

d: 2015-01-01 01:00:00 +0000

- , NSDate, , NSDateFormatter .

, UTC, .; -)

, , NSDates - 1 2001 , , - .

0

All Articles