获取特定时间范围的事件

时间:2016-01-10 17:47:36

标签: c# office365 office365-apps office365api outlook-restapi

我正在使用Office365 Outlook Calendar API。我需要获得特定时间范围的事件。我试图比较foreach命令中的DateTimeTimeZone值,但似乎它只支持一个==运算符:

if ( calendarEvent.Start >= new DateTimeTimeZone()
            {
                TimeZone = TimeZoneInfo.Local.Id,
                DateTime = DateTime.Now.ToString("s")
            })

此代码段失败并显示错误:无法应用运算符'> ='操作类型' Microsoft.Office365.OutlookServices.DateTimeTimeZone'和' Microsoft.Office365.OutlookServices.DateTimeTimeZone'

是否有其他方法可以获取特定时间范围的事件,例如未来事件?

到目前为止,这是我的GetEvents()方法:

    [Route("GetEvents")]
    public async Task GetEvents()
    {
        //Get client
        OutlookServicesClient client = await this.GetClient();

        //Get events
        var events = await client.Me.Events
            .Take(10)
            .ExecuteAsync();

        foreach (var calendarEvent in events.CurrentPage)
        {
            //
            if ( calendarEvent.Subject == "Test 1" )
            {
                System.Diagnostics.Debug.WriteLine("Event '{0}'.", calendarEvent.Subject) ; 
            }
        }
    }

1 个答案:

答案 0 :(得分:1)

您应该使用CalendarView来获取时间范围内的事件。

DateTimeOffset startDateTime, endDateTime;
var events = client.Me.GetCalendarView(startDateTime, endDateTime);
相关问题