创建事件不确认传入的时区

Create event does not acknowledge timezone passed in

我正在使用 Microsoft Graph 创建 event。一切正常,除了它总是在 UTC 中创建事件。我正在按照文档中的示例进行操作,但仍然没有运气。

这是 post 的正文:

{
    "subject": "My event",
    "start": {
        "dateTime": "2017-11-03T04:14:31.883Z",
        "timeZone": "Eastern Standard Time"
    },
    "end": {
        "dateTime": "2017-11-10T05:14:31.883Z",
        "timeZone": "Eastern Standard Time"
    }
}

这是回复:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('...')/events/$entity",
    "@odata.etag": "W/\"1OZnj8JcDU6yRK1K4rYSNQABJ3X/lw==\"",
    "id": "...",
    "createdDateTime": "2017-11-03T04:15:13.7075368Z",
    "lastModifiedDateTime": "2017-11-03T04:15:13.7231636Z",
    "changeKey": "1OZnj8JcDU6yRK1K4rYSNQABJ3X/lw==",
    "categories": [],
    "originalStartTimeZone": "UTC",
    "originalEndTimeZone": "UTC",
    "iCalUId": "...",
    "reminderMinutesBeforeStart": 15,
    "isReminderOn": true,
    "hasAttachments": false,
    "subject": "My event",
    "bodyPreview": "",
    "importance": "normal",
    "sensitivity": "normal",
    "isAllDay": false,
    "isCancelled": false,
    "isOrganizer": true,
    "responseRequested": true,
    "seriesMasterId": null,
    "showAs": "busy",
    "type": "singleInstance",
    "webLink": "...",
    "onlineMeetingUrl": null,
    "responseStatus": {
        "response": "organizer",
        "time": "0001-01-01T00:00:00Z"
    },
    "body": {
        "contentType": "text",
        "content": ""
    },
    "start": {
        "dateTime": "2017-11-03T04:14:31.8830000",
        "timeZone": "UTC"
    },
    "end": {
        "dateTime": "2017-11-10T05:14:31.8830000",
        "timeZone": "UTC"
    },
}

因为 startend 属性表示 dateTimeTimeZone type and DateTime property expect the value to be specified in yyyy-mm-ddThh:mm[:ss[.fffffff]] format (see Edm.DateTime type 描述以获取更多详细信息)。

在您的示例中,Z 需要从 2017-11-10T05:14:31.883Z 中省略,因为 'Z' is the zone designator for the zero UTC offset,这就是 timeZone 属性 被忽略的原因。

例如:

{
  "subject": "My event",
  "start": {
    "dateTime": "2017-11-03T04:14:31.8830000",
    "timeZone": "Eastern Standard Time"
  },
  "end": {
    "dateTime": "2017-11-10T05:14:31.8830000",
    "timeZone": "Eastern Standard Time"
  }
}

此代码片段有效。

invite.Start.TimeZone = eventInvite.TimeZone;
invite.Start.DateTime =  eventInvite.StartDateTime.LocalDateTime.ToString("yyyy-MM-ddTHH:mm:ss.fffffff", System.Globalization.CultureInfo.InvariantCulture);
invite.End.TimeZone = eventInvite.TimeZone;
invite.End.DateTime = eventInvite.EndDateTime.LocalDateTime.ToString("yyyy-MM-ddTHH:mm:ss.fffffff", System.Globalization.CultureInfo.InvariantCulture);