我在使用Parse" moreThanOrEqualTo"查询内容时遇到了问题。并将其与日期进行比较。
我可以成功查询日期格式为" yyyy-MM-dd HH:mm:ss"但不是格式化为Parse中常规createdAt列的日期,格式为" yyyy-MM-dd' H&H:mm:ss.SSSZ"
因此,在我的示例中,如果我在列 date_sent_to_device 中查询匹配日期的记录,它将正常工作,但如果搜索匹配列 createdAt 则不行。
这是我的代码:
let yesterdaycalculatedDate = (Calendar.current as NSCalendar).date(byAdding: NSCalendar.Unit.day, value: -1, to: self.date_route_processed, options: NSCalendar.Options.init(rawValue: 0))
let dateFormatterforYesterday = DateFormatter()
//following works on date_sent_to_device column
dateFormatterforYesterday.dateFormat = "yyyy-MM-dd HH:mm:ss"
//following fails on createdAt column
dateFormatterforYesterday.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
let yesterdaysdate = dateFormatterforYesterday.string(from: yesterdaycalculatedDate!)
let query = PFQuery(className: "orders")
query.whereKey("createdAt", greaterThanOrEqualTo: yesterdaysdate)
以下是我的专栏:
"createdAt": "2018-06-17T21:13:15-04:00",
"date_sent_to_device": "2018-06-17 09:27:48 pm",