【发布时间】:2015-01-23 12:23:37
【问题描述】:
我有一个包含事件和日历的核心数据,我需要构建一个谓词请求以仅获取今天的事件。例如:
事件(在核心数据表中,它是两个日期类型的属性)
1) Start 10/01/2015 14:00:00 Ends 10/01/2015 16:00:00
2) Start 10/01/2015 14:00:00 Ends 11/01/2015 19:00:00
3) Start 09/01/2015 12:00:00 Ends 12/01/2015 16:00:00
4) Start 09/01/2015 12:00:00 Ends 09/01/2015 16:00:00
今天是
10/01/2015
我需要请求返回 3 个事件 (#1-2-3) 并将 #4 排除为:
1) Is Starting today and Ends today
2) Starts today and Ends tomorrow (so it is running today as well)
3) Started yesterday and Ends after tomorrow (so it is running today as well)
4) Is not running today
所以问题是最好的方法是什么?也许有人至少可以提示如何确定今天的开始时间戳和结束时间戳(10/01/2015 00:00:00 和 10/01/2015 24:00:00,如果我是正确的???)
【问题讨论】:
-
所以你在一个字符串中有开始和结束日期?
-
@ClausBönnhoff: No-no) 我在核心日期表中有两个日期类型的属性...
-
那么只获取 startdate 为 today 的数据有什么问题?还是我理解错了?
-
不清楚你在问什么。如果你同时想要 1、2、3 和 4,你只需要使用
NSPredicate来获取,使用NSDateComponents获取昨天和明天的NSDate(可能使用“午夜”,并使用这样的谓词:(startDate >= %@) AND (endDate <= %@), yesterdayDate, tomorrowDate; -
您的问题到底是什么?如何获得代表日期边界的
NSDates?如何构建NSPredicate字符串?
标签: ios cocoa cocoa-touch