gpt4 book ai didi

ios - 输入 NSDate 的格式

转载 作者:行者123 更新时间:2023-11-29 03:31:38 25 4
gpt4 key购买 nike

这就是我向 Ical 添加事件的方式 我只是不知道如何将开始日期设置为当前日期以外的日期,以及将持续时间设置为全天事件。

> EKEventStore *store = [[EKEventStore alloc] init];
> [store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
> if (!granted) { return; }
> EKEvent *event = [EKEvent eventWithEventStore:store];
> event.title = @"Hits THermal DC I";
> event.startDate = [NSDate date]; //today
> event.endDate = [event.startDate dateByAddingTimeInterval:60*60]; //set 1 hour meeting
> [event setCalendar:[store defaultCalendarForNewEvents]];
> NSError *err = nil;
> [store saveEvent:event span:EKSpanThisEvent commit:YES error:&err];
> NSString *savedEventId = event.eventIdentifier; //this is so you can access this event later
> }];

最佳答案

要使用您自己的值创建任何日期,请执行以下操作:

NSCalendar* calendar=[NSCalendar currentCalendar];    

NSDateComponents* dateComps=[[NSDateComponents alloc] init];

[dateComps setYear:1990];
[dateComps setMonth:11];
[dateComps setDay:10];

NSDate* starDate=[calendar dateFromComponents:dateComps];

EKEventStore *store = [[EKEventStore alloc] init];
[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (!granted) { return; }
EKEvent *event = [EKEvent eventWithEventStore:store];
event.title = @"Hits THermal DC I";
event.startDate = starDate
event.endDate = [event.startDate dateByAddingTimeInterval:60*60]; //set 1 hour meeting
[event setCalendar:[store defaultCalendarForNewEvents]];
NSError *err = nil;
[store saveEvent:event span:EKSpanThisEvent commit:YES error:&err];
NSString *savedEventId = event.eventIdentifier; //this is so you can access this event later
}];

关于ios - 输入 NSDate 的格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19695411/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com