0

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 :(

4

2 回答 2

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

到目前为止工作正常。

于 2010-12-21T14:48:57.477 回答
0

您的输入可能正确,但格式化程序不正确。请检查这 2 行。我相信错误在那里

[df setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
NSDate *startdate = [df dateFromString: arg1];
于 2010-12-21T13:56:19.043 回答