Ios 如何在Swift解析中按日期偏移量查询?

Ios 如何在Swift解析中按日期偏移量查询?,ios,swift,parse-platform,Ios,Swift,Parse Platform,我想对一个解析查询设置一个约束,它接受一个生日(日期),并且只收集10年内的结果 所以如果日期是(1954-01-10 07:00:00+0000) 然后我想得到从1944年到1964年的所有记录 是否有一些方法可以使用解析查询代码来实现这一点 或者, 我是否必须获得日期,然后使用swift代码将其抵消10年,然后写下类似的内容 let currentUserBirthday = PFUser.currentUser()?.objectForKey("birthday")! // set da

我想对一个解析查询设置一个约束,它接受一个生日(日期),并且只收集10年内的结果

所以如果日期是(1954-01-10 07:00:00+0000) 然后我想得到从1944年到1964年的所有记录

是否有一些方法可以使用解析查询代码来实现这一点

或者, 我是否必须获得日期,然后使用swift代码将其抵消10年,然后写下类似的内容

let currentUserBirthday = PFUser.currentUser()?.objectForKey("birthday")!

// set date 10 years greater and lower than currentUserBirthday
let datePlus10 =   // add 10 years to date
let dateMinus10 =  // subtract 10 years from date

dailyFourQuery?.whereKey("birthday", greaterThanOrEqualTo: datePlus10)
dailyFourQuery?.whereKey("birthday", lessThanOrEqualTo: dateMinus10)
编辑:嘿,伙计们,我解决了这个问题,从日期开始计算年龄,然后从这个数字上加上或减去整数偏移量, 然后使用NSCalendar并创建具有修改值的组件。 谢谢你的帮助

let currentUserBirthdayNSDate = currentUserBirthday as! NSDate

let dateComponents = calendar.components([NSCalendarUnit.Day, NSCalendarUnit.Month, NSCalendarUnit.Year, NSCalendarUnit.WeekOfYear, NSCalendarUnit.Hour, NSCalendarUnit.Minute, NSCalendarUnit.Second, NSCalendarUnit.Nanosecond], fromDate: currentUserBirthdayNSDate)

let componentsPlus10 = NSDateComponents()
componentsPlus10.day = dateComponents.day
componentsPlus10.month = dateComponents.month
componentsPlus10.year = dateComponents.year + 10
componentsPlus10.hour = dateComponents.hour
componentsPlus10.minute = dateComponents.minute
你可以参考

您想要这个吗?

您可以参考


您想要这个吗?

恐怕您必须在查询中用Swift和user
greater/lessThanEqualTo:
计算这两个日期。据我所知,Parse没有任何用于日期查询的特殊方法。我知道Parse有一种叫做云代码的东西,这可能是解决您问题的方法。除此之外,我不相信他们的API有你想要的功能。好吧。。。谢谢各位。我正在阅读,它似乎有修改日期的好办法。有很多非常方便的日期处理插件。我也做过同样的事情,但它是在目标c中。如果你知道的话,请告诉我。恐怕你必须在查询中用Swift和user
greater/lessThanEqualTo:
计算这两个日期。据我所知,Parse没有任何用于日期查询的特殊方法。我知道Parse有一种叫做云代码的东西,这可能是解决您问题的方法。除此之外,我不相信他们的API有你想要的功能。好吧。。。谢谢各位。我正在阅读,它似乎有修改日期的好办法。有很多非常方便的日期处理插件。我也做过同样的事情,但它是在目标c中。如果你知道,请告诉我。
// Reference date is: Thu, 19 Nov 2015 19:00:00 UTC (1447959600 from 1970)
let refDate = NSDate(timeIntervalSince1970: 1447959600)

// Remember: all parameters are optional; in this example we have ignored minutes and seconds
let newDate = refDate.add(years: 1, months: 2, days: 1, hours: 2)
// newdate is 2017-01-21 14:00:00 +0000

// This is equivalent to
let newDate2 = refDate + 1.years + 2.months + 1.days + 2.hours