首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用AQS按日期和时间在Exchange服务中搜索

使用AQS按日期和时间在Exchange服务中搜索
EN

Stack Overflow用户
提问于 2017-03-21 11:43:38
回答 1查看 611关注 0票数 0

我使用Java,在Exchange服务器中使用AQS字符串搜索消息面临问题。

我需要在一个特定的日期和时间之后收到所有的信息。只是过了一天,一切都很好,当我消磨时间的时候,问题就来了。我不确定我需要在查询中使用什么格式,这一节缺乏文档。

这是我的密码:

代码语言:javascript
复制
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版本

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-21 12:07:03

好吧,我找到解决办法了。

只需添加一个Calendar变量,用DateFormat格式化它,并将其传递给查询字符串:

代码语言:javascript
复制
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());
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42926167

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档