首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将实际日期转换为火灾日期字符串,以便在ios上发出位置通知

将实际日期转换为火灾日期字符串,以便在ios上发出位置通知
EN

Stack Overflow用户
提问于 2013-01-27 19:50:17
回答 1查看 578关注 0票数 0

让我再试一次,说得更清楚,我很抱歉。\我正试图在iOS中的照片分配应用程序中添加一个特定日期的提醒。我很希望能拿到它,这样它就会提醒他们一年的确切日期,让他们知道一年中那个时候的任务。

例如:

12月31日-新年前夜-放烟花,7月1日派对-加拿大日-拍摄庆祝活动,10月30日烟花-万圣节之前-拍摄南瓜,服装12月15日-圣诞彩灯!

等。

我已经有一个每日提醒设置,每天早上9点触发,提醒他们得到一个分配,这是打开或关闭的用户希望通过设置包中的切换开关。我还想再来一次“假日提醒”

以下是每日提醒的当前代码:

代码语言:javascript
复制
NSDateComponents *dateComponents = [calender components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit)
                                                       fromDate:currentDate];

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

        [temp setYear:[dateComponents year]];
        [temp setMonth:[dateComponents month]];
        [temp setDay:[dateComponents day]];
        [temp setHour: 9];
        [temp setMinute:00];

        NSDate *fireTime = [calender dateFromComponents:temp];
        [temp release];

        // set up the notifier 
        UILocalNotification *localNotification = [[UILocalNotification alloc]init];

        localNotification.fireDate = fireTime;
        localNotification.timeZone = [NSTimeZone defaultTimeZone];

如何将实际日期(12月31日)转换为fireDate =变量/字符串?

我希望这一点更清楚。我已经搜索过了,但一直找不到答案。谢谢

诺埃尔·切尼尔

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-28 01:40:01

您只需要在创建fireTime时手动指定年份、月份和日期。

代码语言:javascript
复制
NSDateComponents *dateComponents = [calender components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit)
                                                   fromDate:currentDate];

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

    [temp setYear:2013];
    [temp setMonth:12];
    [temp setDay:31];
    [temp setHour: 9];
    [temp setMinute:00];

    NSDate *fireTime = [calender dateFromComponents:temp]; // December 31st 2013 9:00
    [temp release];

    // set up the notifier 
    UILocalNotification *localNotification = [[UILocalNotification alloc]init];

    localNotification.fireDate = fireTime;
    localNotification.timeZone = [NSTimeZone defaultTimeZone];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14551496

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档