2017-10-19 66 views
1

我對使用Outlook API特別與Calendar API有關的問題。日曆中的Outlook 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?

謝謝!

回答

2

如果你希望你的事件開始日期是二零一七年十月十九日在10:30本地時間,你的起始對象應該是這樣的:

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

這是你的起始對象是什麼樣子?如果確實如此,則應在日曆中正確顯示事件時間。

3

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" 
    } 
} 

無論是在迴應我的職務,併爲事件後續GET請求,我回來:

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

改變時區爲UTC後,問題仍然存在。我發現它不起作用。在網絡郵件中,雖然我在註冊時填寫了正確的時區,但時區設置爲UTC-8 ... 感謝您的回答!