日历中的 Outlook API 时差



我在使用 Outlook API 时遇到问题,特别是日历 API。

我使用 UTC 格式发送日期,当它们添加到日历中时,我与发送日期有所不同。

我在法国,所以原始日期是 UTC+2。我以 UTC 格式转换并使用此配置提出请求:

var options = {
            url: "https://outlook.office.com/api/v2.0/me/calendars/" + workspace.calendarId + "/events?$Select=Id",
            method: "POST",
            headers: {
                "authorization": "Bearer " + host.outlookCalAccessToken,
                "accept" : "application/json",
                "ContentType" : "application/json"
            },
            json:{
                "Subject" : event.summary,
                "Body" : {
                    "ContentType" : "Text",
                    "Content" : event.description
                },
                "Start" : {
                    "DateTime":start,
                    "TimeZone" : "OriginStartTimeZone"
                },
                "End" : {
                    "DateTime":end,
                    "TimeZone" : "OriginStartTimeZone"
                },
                "Attendees" : [
                    {
                        "EmailAddress" : {
                            "Name" : nomad.firstname,
                            "Address" : nomad.email
                        },
                        "Type" : "Required"
                    }
                ]
            },
            "Content-Type" : "application/json"
        };

如果时区是"OriginStartTimeZone"或"UTC",我也有同样的问题。

例如,我的本地日期是2017-10-19T17:00:00.000它被转换为 UTC 2017-10-19T15:00:00.000Z在日历中,事件日期是2017-10-19T08:00:00.000

我错过了这个 API 的什么?

谢谢!

OriginStartTimeZone 不是 TimeZone 的有效值。如果将TimeZone设置为 UTC则应获得预期的结果。我刚刚在这里用这个有效载荷测试了它:

{
    "Subject" : "test",
    "Body" : {
        "ContentType" : "Text",
        "Content" : "hello"
    },
    "Start" : {
        "DateTime": "2017-10-19T15:00:00.000Z",
        "TimeZone" : "UTC"
    },
    "End" : {
        "DateTime": "2017-10-19T16:00:00.000Z",
        "TimeZone" : "UTC"
    }
}

在对我的 POST 和随后对该事件的 GET 请求的响应中,我都得到了:

"Start": {
    "DateTime": "2017-10-19T15:00:00.0000000",
    "TimeZone": "UTC"
},
"End": {
    "DateTime": "2017-10-19T16:00:00.0000000",
    "TimeZone": "UTC"
},

如果您希望事件开始日期为当地时间 2017-10-19 10:30,则开始对象应如下所示:

Start:{DateTime: "2017-10-19T10:30:00+02:00", TimeZone: "UTC"}

这是您的起始对象的样子吗?如果是这样,则应在日历中正确显示事件时间。

时区更改为 UTC 后,问题仍然存在。我发现了它不起作用的东西。在网络邮件中,时区设置为 UTC-8,尽管我在注册时填写了正确的时区......感谢您的回答!

最新更新