如何在Parse.com数据库上进行查询,只获取最长1小时的条目?
我有这段代码:
@Override
protected Void doInBackground(Void... params) {
String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());
ParseQuery<ParseObject> query = ParseQuery.getQuery("AlertsClass");
query.orderByDescending("_created_at");
query.whereGreaterThanOrEqualTo("_created_at", currentDateTimeString);
try {
ob = query.find();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
但我被困住了。有人可以帮我正确地进行这个查询吗?
谢谢!
答案 0 :(得分:1)
这样的事情应该有效:
Date now = new Date());
long nowMillis = now.getTime();
long oneHourInMills = 3600000;
Date anHourAgo = new Date(nowMillis - oneHourInMillis);
ParseQuery<ParseObject> query = ParseQuery.getQuery("AlertsClass");
query.orderByDescending("createdAt");
query.whereGreaterThanOrEqualTo("createdAt", anHourAgo);