以下是重现该错误的步骤:
获取 https://outlook.office.com/api/v1.0/me/calendarview?startDateTime=2016-01-25T01:00:00Z&endDateTime=2016-02-01T23:00:00Z
{
"@odata.context":"https://outlook.office.com/api/v1.0/$metadata#Me/CalendarView",
"value":[
{
"@odata.id":"NOT IMPORTANT",
"@odata.etag":"NOT IMPORTANT",
"Id":"NOT IMPORTANT",
"DateTimeCreated":"2016-01-20T20:48:49.3867149Z",
"DateTimeLastModified":"2016-01-20T20:48:49.4179638Z",
"ChangeKey":"NOT IMPORTANT",
"Categories":[
],
"StartTimeZone":"UTC",
"EndTimeZone":"UTC",
"ResponseStatus":{
"Response":"Organizer",
"Time":"0001-01-01T00:00:00Z"
},
"iCalUId":"NOT IMPORTANT",
"Reminder":null,
"HasAttachments":false,
"Subject":"My all day event, in EST",
"Body":{
"ContentType":"HTML",
"Content":"<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<style type=\"text/css\" style=\"\">\r\n<!--\r\np\r\n\t{margin-top:0;\r\n\tmargin-bottom:0}\r\n-->\r\n</style>\r\n</head>\r\n<body dir=\"ltr\">\r\n<div id=\"divtagdefaultwrapper\" style=\"font-size:12pt; color:#000000; background-color:#FFFFFF; font-family:Calibri,Arial,Helvetica,sans-serif\">\r\n<p><br>\r\n</p>\r\n</div>\r\n</body>\r\n</html>\r\n"
},
"BodyPreview":"",
"Importance":"Normal",
"Sensitivity":"Normal",
"Start":"2016-01-26T00:00:00Z",
"End":"2016-01-27T00:00:00Z",
"Location":{
"DisplayName":""
},
"IsAllDay":true,
"IsCancelled":false,
"IsOrganizer":true,
"Recurrence":null,
"ResponseRequested":true,
"SeriesMasterId":null,
"ShowAs":"Busy",
"Type":"SingleInstance",
"Attendees":[
],
"Organizer":{
"EmailAddress":{
"Name":"brett",
"Address":"NOT IMPORTANT"
}
},
"WebLink":"NOT IMPORTANT"
}
]
}
我希望开始和结束时间准确到东部标准时间的开始和结束时间
"Start":"2016-01-26T05:00:00Z",
"End":"2016-01-27T05:00:00Z",
最佳答案
您也可以轻松地从 v1 API 获取数据,
您只需要确保在要求时间时您正在通过UTC
时区和获取信息,您需要指定您期望的时区。
$date = new DateTime("now", new DateTimeZone('UTC') );
$deviceTimeStart = $date->format('Y-m-d\TH:i:s\Z');
$deviceTimeEndPlus1 = $date->modify('+1 minutes');
$deviceTimeEnd = $deviceTimeEndPlus1->format('Y-m-d\TH:i:s\Z');
$httpHeader = array(
"authorization: Bearer *****access_token*****",
"cache-control: no-cache",
"Prefer : outlook.timezone = \"Asia/Kolkata\""
);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://graph.microsoft.com/v1.0/me/calendarview?startDateTime='.$TimeStart.'&endDateTime='.$TimeEnd.'&$select=Subject,Organizer,Start,End,bodyPreview,changeKey,location,attendees,organizer,lastModifiedDateTime',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => $httpHeader,
)
);
$curlResponse = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
$responseNew = (array) json_decode($curlResponse, true);
关于json - Office 365 API 为全天事件返回不正确的开始和结束日期时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34910743/