开发者

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


Your input maybe correct but the formatter is not. Please, review these 2 lines. I believe the bug is there

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


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

is working fine so far.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜