JDOQL / Java / GAE中按日期时间查询
我正在开发 GAE 应用程序。我想查询数据存储并检索开始日期和结束日期之间的所有记录。每条记录都有一个日期时间字段。我正在使用与此类似的查询(下面的代码是我快速抓取的代码 - 我不在我的开发机器附近。):
Query query = pm.newQuery(Employee.class);
query.setFilter("lastName == lastNameParam");
query.setOrdering("hireDate desc");
query.declareParameters("String lastNameParam");
try {
List results = (List) query.execute("Smith");
if (results.iterator().hasNext()) {
for (Employee e : results) {
// ...
}
} else {
// ... no results ...
}
} finally {
query.closeAll();
}
我如何格式化日期以形成正确工作的查询?日期时间戳如何存储在数据存储中?作为时间戳?完全格式化了吗?我找不到这方面的任何信息。请帮忙。
I'm working on a GAE app. I want to query datastore and retrieve all records between startDate and endDate. Each record has a datetime field. I'm using a query similar to this (the below code is something I quickly grabbed - I'm not near my developer machine.):
Query query = pm.newQuery(Employee.class);
query.setFilter("lastName == lastNameParam");
query.setOrdering("hireDate desc");
query.declareParameters("String lastNameParam");
try {
List results = (List) query.execute("Smith");
if (results.iterator().hasNext()) {
for (Employee e : results) {
// ...
}
} else {
// ... no results ...
}
} finally {
query.closeAll();
}
How do I have to format the date to form a correctly working query? How is the datetime stamp stored in datastore? As timestamp? Fully formatted? I can't find ANY information on this. Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 google datastore 低级 API, 日期对象似乎可以在 GAE 中自由存储。因此,我认为使用 java.util.Date (或 javax.sql.Date,它并不完全明确)可以完成这项工作。
According to google datastore low-level API, Date Objects seems to be freely storable in GAE. As a consequence, using java.util.Date (or javax.sql.Date, it's not totally explicit) will do the job, i think.
您还可以使用时间戳
You can also use timestamp