我使用Java,在Exchange服务器中使用AQS字符串搜索消息面临问题。
我需要在一个特定的日期和时间之后收到所有的信息。只是过了一天,一切都很好,当我消磨时间的时候,问题就来了。我不确定我需要在查询中使用什么格式,这一节缺乏文档。
这是我的密码:
protected static void searchByCategoryAndDateOldVersion() throws Exception{
ItemView view = new ItemView(Integer.MAX_VALUE);
view.getOrderBy().add(ItemSchema.DateTimeReceived, SortDirection.Ascending);
String aqs = "category:categoryToSearch AND received:>=2017-03-21T10:35:00";
FindItemsResults<Item> findResults = service.findItems(WellKnownFolderName.Inbox, aqs, view);
service.loadPropertiesForItems(findResults, PropertySet.FirstClassProperties);
System.out.println("Items found: " + findResults.getTotalCount());
for (Item item : findResults) {
System.out.println(item.getSubject());
}
}正如我说过的,如果我设置不带T10:35:00部分的param,一切都可以工作。
我如何告诉EWS在那个特定的时间之后只检索消息?
我必须使用AQS作为我使用的SearchFilter不支持类别搜索的Exchange版本
发布于 2017-03-21 12:07:03
好吧,我找到解决办法了。
只需添加一个Calendar变量,用DateFormat格式化它,并将其传递给查询字符串:
protected static void searchByCategoryAndDateOldVersion() throws Exception{
ItemView view = new ItemView(Integer.MAX_VALUE);
view.getOrderBy().add(ItemSchema.DateTimeReceived, SortDirection.Ascending);
Calendar calendar = new GregorianCalendar(2017, 2, 21, 10, 35, 0);
Date time = calendar.getTime();
DateFormat dateFormat = new SimpleDateFormat();
String dateLimit = dateFormat.format(time);
String aqs = String.format("category:categoryToSearch AND received:>=%s", dateLimit);
FindItemsResults<Item> findResults = service.findItems(WellKnownFolderName.Inbox, aqs, view);
service.loadPropertiesForItems(findResults, PropertySet.FirstClassProperties);
System.out.println("Items found: " + findResults.getTotalCount());
for (Item item : findResults) {
System.out.println(item.getSubject());
}
}https://stackoverflow.com/questions/42926167
复制相似问题