我是初学者,所以请在解释时保持友好,谢谢。
所以基本上我试图使用createdAt来获取今天制作的对象。
let parseQuery = PFQuery(className: "request")
parseQuery.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
if let objects = objects {
for object in objects {
self.reqDates.append(object.createdAt!)
}
}
}
let formatter = NSDateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:mm"
let formatteddate = formatter.stringFromDate(self.reqDates[indexPath.row])
myCell.reqDate.text = formatteddate
当我执行此操作时,它会正确显示所有具有日期的对象。但是,我怎样才能显示今天的对象,而不是所有对象都被创建。 我希望我解释得足够好。
答案 0 :(得分:0)
createdAt
大于今天(午夜)的请求对象
let parseQuery = PFQuery(className: "request")
let cal = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!
let components = cal.components([.Day , .Month, .Year ], fromDate: NSDate())
let todayDate = cal.dateFromComponents(components)
parseQuery.whereKey("createdAt", greaterThan:todayDate!)
parseQuery.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
if let objects = objects {
for object in objects {
print(object.createdAt)
}
}
}