Search code examples
iphoneeventsnsdateeventkit

date problem while adding Event to iPhone calendar


while adding an event to the calendar of an iphone, the date is going to be reseted to 1.1.2001 and i have no idea why.

id arg1 = [args objectAtIndex:0];  // start
id arg2 = [args objectAtIndex:1];  // end
id arg3 = [args objectAtIndex:2];  // title
id arg4 = [args objectAtIndex:3];  // location
id arg5 = [args objectAtIndex:4];  // text

NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
NSDate *startdate = [df dateFromString: arg1];
NSDate *enddate = [df dateFromString: arg2];

EKEventStore *eventStore = [[[EKEventStore alloc] init] autorelease];

EKEvent *event  = [EKEvent eventWithEventStore:eventStore];

event.title     = arg3;
event.location  = arg4;
event.notes     = arg5;
event.startDate = startdate;
event.endDate   = enddate;



[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];

the input seems to be fine since

NSLog([args objectAtIndex:0]);

writes the correct date. i have no real idea :(


Solution

  • [df setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
    

    is working fine so far.