如何获取 iPhone 中过去和未来日期的值

发布于 2024-11-19 23:02:59 字数 239 浏览 2 评论 0原文

我正在制作一个应用程序,其中我从服务器获取一些事件响应,如果有一些日期与该事件相关,我需要知道如何区分这两个日期,在我的应用程序中有两个分段栏,第一个是即将发生的事件,第二个是过去的事件,现在我需要以这种格式显示与日期相关的事件,意味着下一个事件即将到来,需要在即将发生的事件中显示,而已经发生的事件需要显示在过去的事件中,所有日期均来自网络服务器dd/mm/year 格式,我已将所有日期存储在数组中并将它们显示在表格中,但是如何区分即将到来的日期和过去的日期。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

2024-11-26 23:02:59
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;
}
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;
}
放赐 2024-11-26 23:02:59

请阅读“日期和时间编程指南”。这是解决您所有问题的绝佳资源。我强烈推荐您章节“从组件创建日期" 和 "历法计算”。

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".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文