设置2小时到结束时间日期

时间:2012-05-10 12:44:06

标签: iphone objective-c cordova

我第一次尝试编辑某个目标-c。
我正在尝试编辑将日历添加到iPhone日历中的phonegap日历插件,但由于我的日期没有结束时间,我想编辑它以便自动设置结束时间开始时间后2小时

NSString* title      = [arguments objectAtIndex:1];
NSString* location   = [arguments objectAtIndex:2];
NSString* message    = [arguments objectAtIndex:3];
NSString *startDate  = [arguments objectAtIndex:4];
//NSString *endDate    = [arguments objectAtIndex:5];

//creating the dateformatter object
NSDateFormatter *sDate = [[[NSDateFormatter alloc] init] autorelease];
[sDate setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *myStartDate = [sDate dateFromString:startDate];

//NSDateFormatter *eDate = [[[NSDateFormatter alloc] init] autorelease];
//[eDate setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
//NSDate *myEndDate = [eDate dateFromString:endDate];
NSDate *myEndDate = [myStartDate dateByAddingTimeInterval:  2*60*60];

myEvent.title = title;
myEvent.location = location;
myEvent.notes = message;
myEvent.startDate = myStartDate;
myEvent.endDate = myEndDate;
myEvent.calendar = store.defaultCalendarForNewEvents;

我没有收到任何错误,但是当我测试我的应用时,它不再将日期添加到日历中。

0 个答案:

没有答案