我需要根据昨天添加的值过滤搜索结果。我昨天看到很多使用:
NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents *components = [cal components:( NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit ) fromDate:[[NSDate alloc] init]];
[components setHour:-24];
[components setMinute:0];
[components setSecond:0];
NSDate *yesterday = [cal dateByAddingComponents:components toDate:[NSDate date] options:0];
predicate = [NSPredicate predicateWithFormat:@"created_at >= %@", yesterday];
但这会从这个确切的时间点算起 24 小时。我需要过滤昨天的 12:01am-12:00pm。所以昨天的实际 24 小时时段。
我猜我需要按照以下方式做一些事情: 1. 取当前日期 2. 查找从当前日期到同一天凌晨 12:01 的时间 3. 然后从该日期减去 24 小时
我有信心我可以做到#3(当然还有#1),但我不确定如何去做#2。我可能想多了,但我似乎无法掌握如何说:“好的,现在是上午 8:03,我需要删除 8 小时 2 分钟,这将使我在上午 12:01”。