本月仅解析

时间:2016-01-09 08:51:00

标签: objective-c parse-platform

我是新手解析,我需要帮助检索当月的对象。 首先,我有一个名为food的类,并且有一个名为Date的{​​{1}}类型的列

我假设我必须使用更大而且更少,但我不确定如何。

food_date

1 个答案:

答案 0 :(得分:0)

我认为你需要这样的东西:

NSCalendar *calendar = [NSCalendar currentCalendar];

NSDateComponents *components = [calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth |  NSCalendarUnitDay) fromDate:[NSDate date]];

components.day = 1;

// Get the date of the first day of the current month
NSDate *minimumDate = [calendar dateFromComponents:components];

components.month = components.month + 1;

// Get the date of the first day of the next month
NSDate *maximumDate = [calendar dateFromComponents:components];

PFQuery *foodList = [PFQuery queryWithClassName:@"food"];
[foodList whereKey:@"food_date" greaterThanOrEqualTo:minimumDate];
[foodList whereKey:@"food_date" lessThan:maximumDate];

[foodList findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error) {
        // The find succeeded.
        NSLog(@"Successfully retrieved %d foods.", objects.count);

        // Do something with the found objects
        for (PFObject *object in objects) {
            NSLog(@"%@", object.objectId);
        }
    } else {
        // Log details of the failure
        NSLog(@"Error: %@ %@", error, [error userInfo]);
    }
}];

我希望有所帮助。