嗨,我制作了一个按钮,让您可以添加日历事件,但我想获取 12 小时制的日期,并使用按钮在上午和下午之间切换。
这是日历事件的代码:
- (IBAction)agregaevento:(id)sender {
NSString *d1 = dia.text;
NSString *m1 = mes.text;
NSString *a1 = anio.text;
NSString *h1 = hora.text;
NSString *m2 = minutos.text;
NSString *fechadelevento = [NSString stringWithFormat:@"%@-%@-%@ %@:%@", d1, m1, a1,h1,m2];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"America/Montevideo"]];
[dateFormatter setDateFormat:@"dd-MMM-yyyy hh:mm"];
[Dateevento addObject:fechadelevento];
NSDate *myDate=[dateFormatter dateFromString:fechadelevento];
EKEventStore *store = [[EKEventStore alloc]init];
EKEventStore *eventStore = [[EKEventStore alloc] init];
EKEvent *myEvent = [EKEvent eventWithEventStore:store];
myEvent.title = ddText.text;
myEvent.startDate = myDate;
myEvent.endDate = myDate;
[myEvent setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[store saveEvent:myEvent span:EKSpanThisEvent error:&err];
}