C# CalendarView StartDateTime是否始终以UTC为单位?

C# CalendarView StartDateTime是否始终以UTC为单位?,c#,microsoft-graph-api,microsoft-graph-sdks,C#,Microsoft Graph Api,Microsoft Graph Sdks,我正在使用图形客户端sdk。使用startDateTime=2019-11-20T10:00:00.0000000和endDateTime=2019-11-20T23:00:00.0000000调用CalendarView 在我进一步讨论之前,没有一件事是全天进行的。许多事件会再次发生,所以这就是为什么我不使用Events端点,而是使用CalendarView 通过设置preference,outlook.timezone=“Eastern Standard Time”,我为日历事件设置了时区,

我正在使用图形客户端sdk。使用
startDateTime
=
2019-11-20T10:00:00.0000000
endDateTime
=
2019-11-20T23:00:00.0000000
调用CalendarView

在我进一步讨论之前,没有一件事是全天进行的。许多事件会再次发生,所以这就是为什么我不使用Events端点,而是使用CalendarView

通过设置preference,
outlook.timezone=“Eastern Standard Time”
,我为日历事件设置了时区,没有问题。我可以看到东部标准时间的活动开始和结束时间

然而,这些事件并不正确。我有一个活动在美国东部时间上午8:00开始,一个活动在美国东部时间下午6:30开始

  • 上午8:00的会议显示——因为我的开始标准是上午10点,所以不应该这样做。没什么大不了的,但可能是因为它在上午10点结束

  • 下午6:30的会议没有显示,应该是这样,因为我的结束时间是晚上11:00。这是一个问题

  • 如果我将6:30会议推迟到6:00,它将显示在集合中

所以我在想,既然我是
UTC-5
startDateTime
被锁定在UTC时间。它不经过报头时区。我知道上面提到的报头时区是有效的,因为如果我设置了报头,我的事件的实际开始/结束将显示为Eastern,如果我没有设置,则显示UTC

我找不到任何允许我强制calendarview的内容?
$select=subject,start,end&startDateTime=2019-11-20T10:00:00.0000000&endDateTime=2019-11-20T23:30:00.0000000
使用我的本地时间

我在Graph Explorer中对此进行了研究,发现我可以在时间之后放置
-5
,并且它似乎可以工作。我仍然参加上午8:00的活动,但我也参加了6:30的活动。我不想在我的代码中这样做,因为那样我会强迫其他用户使用我的时区

有人知道可以更改什么设置来强制CalendarView使用本地时间作为参数吗?很抱歉,我是graph client的新手,因此可能没有使用正确的词汇表

代码:


GraphServiceClient graphClient=新的GraphServiceClient(AuthProvider);
DateTime d=DateTime.Now.ToLocalTime();
DateTime.SpecifyKind(d,DateTimeKind.Unspecified).ToString(“o”);
字符串MicrosoftDateTimeFormat=“yyyy'-'MM'-'dd'T'HH':'MM':'ss.”“fffffff”;
var start=d.ToString(MicrosoftDateTimeFormat);
var end=d.ToString(“yyyy'-'MM'-'dd'T'23:59:59.0”)//“2019-07-24T23:00:00.0”//
start=“2019-11-20T10:00:00.0000000”//仅用于调试
end=“2019-11-20T23:00:00.0000000”//仅用于调试
列表选项=新列表
{
新查询选项(“startDateTime”,开始),
新查询选项(“endDateTime”,end),
新的查询选项(“orderby”、“start/dateTime”)
};
var events=wait graphClient.Me.CalendarView
.请求(选项)
.Header(“首选”、“outlook.timezone=\”“+TimeZoneInfo.Local.Id+”\“”)
.选择(e=>new
{
e、 主题,,
e、 身体,
e、 车身预览,
e、 组织者,
e、 与会者:,
e、 开始,
e、 完,,
e、 位置
})
.GetAsync();

好的,我让它工作了。今天早上我登记入住时,答案出现在相关问题中

就像他们说的,在罗马的时候……在我的情况下,在UTC的时候,就像UTC的人一样。所以我只是把一切都安排在UTC时间。我确实得出结论,CalendarView请求的日期时间(开始和结束)是UTC时间,显然无法更改。所以我只留下UTC的当前时间戳。我仅在UI中显示事件开始/结束时间时将时间更改为本地时间。无中生有!哈哈

注意:它仍然保留了我上午8点的会议,但这不是一个杀手。我希望我知道为什么,但那是另一天

如果这能帮助像我这样的新手,我的最后一段代码是:

 GraphServiceClient graphClient = new GraphServiceClient(AuthProvider);

        DateTime d = DateTime.UtcNow; //DateTime.Now.ToLocalTime();
        //d = DateTime.Parse("11/20/2019 08:14:34 PM"); //for debug only

        DateTime.SpecifyKind(d, DateTimeKind.Unspecified).ToString("o");
        string MicrosoftDateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffff";
        var start = d.ToString(MicrosoftDateTimeFormat);
        var end = d.ToString("yyyy'-'MM'-'dd'T'23:59:59.9");            //"2019-07-24T23:00:00.0";//

        //start = "2019-11-20T10:00:00.0000000"; //for debug only
        //end = "2019-11-20T23:59:59.0000000";   //for debug only
        //var link = $"https://graph.microsoft.com/v1.0/me/calendarview?startdatetime={start}&enddatetime={end}&orderby=start/dateTime";  //not used. was previously used for http call; before moving to sdk.
        List<Option> options = new List<Option>
        {
            new QueryOption("startDateTime", start),
            new QueryOption("endDateTime", end),
            new QueryOption("orderby", "start/dateTime")
        };

        var events = await graphClient.Me.CalendarView
        .Request(options)
        //.Header("Prefer", "outlook.timezone=\"" + TimeZoneInfo.Local.Id + "\"")            
        .Select(e => new
        {
            e.Subject,
            e.Body,
            e.BodyPreview,
            e.Organizer,
            e.Attendees,
            e.Start,
            e.End,
            e.Location
        })            
        .GetAsync();
GraphServiceClient-graphClient=新的GraphServiceClient(AuthProvider);
DateTime d=DateTime.UtcNow//DateTime.Now.ToLocalTime();
//d=DateTime.Parse(“2019年11月20日08:14:34下午”)//仅用于调试
DateTime.SpecifyKind(d,DateTimeKind.Unspecified).ToString(“o”);
字符串MicrosoftDateTimeFormat=“yyyy'-'MM'-'dd'T'HH':'MM':'ss.”“fffffff”;
var start=d.ToString(MicrosoftDateTimeFormat);
var end=d.ToString(“yyyy'-'MM'-'dd'T'23:59:59.9”)//“2019-07-24T23:00:00.0”//
//start=“2019-11-20T10:00:00.0000000”//仅用于调试
//end=“2019-11-20T23:59:59.0000000”//仅用于调试
//变量链接=$”https://graph.microsoft.com/v1.0/me/calendarview?startdatetime={start}&enddatetime={end}&orderby=start/dateTime”//没有用。以前用于http调用;在转到sdk之前。
列表选项=新列表
{
新查询选项(“startDateTime”,开始),
新查询选项(“endDateTime”,end),
新的查询选项(“orderby”、“start/dateTime”)
};
var events=wait graphClient.Me.CalendarView
.请求(选项)
//.Header(“首选”、“outlook.timezone=\”“+TimeZoneInfo.Local.Id+”\“”)
.选择(e=>new
{
e、 主题,,
e、 身体,
e、 车身预览,
e、 组织者,
e、 与会者:,
e、 开始,
e、 完,,
e、 位置
})            
.GetAsync();

首选:outlook.timezone=“Eastern Standard Time”标题仅影响API响应。您的标头将确保在EST中返回结果,但在检索结果后会发生时区转换。在后端,每个事件都存储为
UTC-0

为了请求给定时区范围内的事件,需要使用将该时区编码为
startTime
endTime
 GraphServiceClient graphClient = new GraphServiceClient(AuthProvider);

        DateTime d = DateTime.UtcNow; //DateTime.Now.ToLocalTime();
        //d = DateTime.Parse("11/20/2019 08:14:34 PM"); //for debug only

        DateTime.SpecifyKind(d, DateTimeKind.Unspecified).ToString("o");
        string MicrosoftDateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffff";
        var start = d.ToString(MicrosoftDateTimeFormat);
        var end = d.ToString("yyyy'-'MM'-'dd'T'23:59:59.9");            //"2019-07-24T23:00:00.0";//

        //start = "2019-11-20T10:00:00.0000000"; //for debug only
        //end = "2019-11-20T23:59:59.0000000";   //for debug only
        //var link = $"https://graph.microsoft.com/v1.0/me/calendarview?startdatetime={start}&enddatetime={end}&orderby=start/dateTime";  //not used. was previously used for http call; before moving to sdk.
        List<Option> options = new List<Option>
        {
            new QueryOption("startDateTime", start),
            new QueryOption("endDateTime", end),
            new QueryOption("orderby", "start/dateTime")
        };

        var events = await graphClient.Me.CalendarView
        .Request(options)
        //.Header("Prefer", "outlook.timezone=\"" + TimeZoneInfo.Local.Id + "\"")            
        .Select(e => new
        {
            e.Subject,
            e.Body,
            e.BodyPreview,
            e.Organizer,
            e.Attendees,
            e.Start,
            e.End,
            e.Location
        })            
        .GetAsync();