本文介绍了获取特定时间范围内的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm working with the Office365 Outlook Calendar API. I need to get events of a specific time range. I tried to compare the DateTimeTimeZone values inside of the foreach command, but it seems like it only supports a == operator:

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

此代码段失败,并出现错误:无法将运算符'> ='应用于类型为'Microsoft.Office365.OutlookServices.DateTimeTimeZone'和'Microsoft.Office365.OutlookServices.DateTimeTimeZone'的操作数

This code snippet fails with the error: Cannot apply operator '>=' to operands of type 'Microsoft.Office365.OutlookServices.DateTimeTimeZone' and 'Microsoft.Office365.OutlookServices.DateTimeTimeZone'

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

Are there any other ways get events of a specific time range, e.g. future events?

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

This is my GetEvents()-method so far:

    [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) ;
            }
        }
    }

推荐答案

您应该使用CalendarView获取某个时间范围内的事件.

You should use the CalendarView to get events within a time range.

DateTimeOffset startDateTime, endDateTime;
var events = client.Me.GetCalendarView(startDateTime, endDateTime);

这篇关于获取特定时间范围内的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 18:25