开发者

How to get the values of past and coming dates in iPhone

开发者 https://www.devze.com 2023-03-19 22:22 出处:网络
I am making an appplication in which i am getting some event response from the server, in the event there are some dates开发者_运维问答 coming related to that event, i need to know how to differentiat

I am making an appplication in which i am getting some event response from the server, in the event there are some dates开发者_运维问答 coming related to that event, i need to know how to differentiate between the two dates, In my application there are two segment bars, first one is upcoming events, and second is past events, now i need to show the event related to date in such format, means event is coming in next, need to be show in upcoming events and the events which have gone need to show in past event, All the date are coming from webserver in dd/mm/year format, i have stored all the dates in array and display them in table, however how to differentiate between the coming date and past dates.


NSDate *firstDate = ...
NSDate *secondDate = ...

NSDate *myDate = [NSDate date];

switch ([myDate compare:firstDate]) {
    case NSOrderedAscending:
        NSLog(@"myDate is older");
        // do something
        break;
    case NSOrderedSame:
        NSLog(@"myDate is the same as firstDate");
        // do something
        break;
    case NSOrderedDescending:
        NSLog(@"myDate is more recent");
        // do something
        break;
}

switch ([myDate compare:secondDate]) {
    case NSOrderedAscending:
        NSLog(@"myDate is older");
        // do something
        break;
    case NSOrderedSame:
        NSLog(@"myDate is the same as secondDate");
        // do something
        break;
    case NSOrderedDescending:
        NSLog(@"myDate is more recent");
        // do something
        break;
}


Please read the "Date and Time Programming Guide". It's a great resource for all of your questions. I'd highly recommend you chapters "Creating a Date from Components" and "Calendrical Calculations".

0

精彩评论

暂无评论...
验证码 换一张
取 消