English 中文(简体)
日期: Telephone SDK
原标题:If/Else statement for Date..iPhone SDK
  • 时间:2010-08-14 22:30:35
  •  标签:
  • iphone

我这里有这样一条法典。 我将如何写一下,以确定该项目是否已经通过? 因此,如果项目日期已经过去,则当地宣布火力。 日期应为现在,加上86400(24小时)其他假期。

NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
        NSDateComponents *dateComps = [[NSDateComponents alloc] init];
        [dateComps setDay:item.day];
        [dateComps setMonth:item.month];
        [dateComps setYear:item.year];
        [dateComps setHour:item.hour];
        [dateComps setMinute:item.minute];
        NSDate *itemDate = [calendar dateFromComponents:dateComps];
        [dateComps release];
        UILocalNotification *localNotif = [[UILocalNotification alloc] init];
        if (localNotif == nil)
            return;

        localNotif.fireDate = [itemDate dateByAddingTimeInterval:-(minutesBefore*60)] ;
            NSLog(@"fireDate is %@",localNotif.fireDate);

        localNotif.timeZone = [NSTimeZone defaultTimeZone];
最佳回答
  1. You can retrieve the current date using [NSDate date].
  2. NSDate has this really convenient method called laterDate: that compares a date with the receiver and returns which ever one is later.
  3. You can see if two dates are equal using isEqual:

换言之:

NSDate * notificationDate = [localNotif fireDate];
NSDate * now = [NSDate date];

if ([[now laterDate:notificationDate] isEqual:now]) {
  //in a comparison between "now" and "notificationDate", "now" is the later date,
  //meaning "notificationDate" has already passed
  notificationDate = [notificationDate dateByAddingTimeInterval:86400];
}
[localNotif setFireDate:notificationDate];
问题回答

暂无回答




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签