Question:
I am currently integrating the Microsoft Graph API for calendar event management within my application. When creating events using the API, I specify the start and end times in the local time zone (America/New_York
), but I've noticed that the response from the API shows the event times in UTC. Here are the details of my implementation:
Controller (Request Body):
{
"title": "American Event",
"startTime": "2024-05-15T22:00:00Z",
"endTime": "2024-05-15T22:30:00Z",
"timeZone": "America/New_York",
"participants": [
{
"email": "stephenignatiusbiz@gmail.com",
"isOrganizer": false,
"status": "needsAction"
}
]
}
Controller (Formatted Request):
`javascript
const formattedRequest = {
subject: 'American Event',
start: { dateTime: '2024-05-15T22:00:00Z', timeZone: 'America/New_York' },
end: { dateTime: '2024-05-15T22:30:00Z', timeZone: 'America/New_York' },
attendees: [
{
emailAddress: {
address: 'stephenignatiusbiz@gmail.com',
name: ''
},
type: 'required'
}
]
};
Service (Graph API Call):
const eventsResponse = await axios.post(
`https://graph.microsoft.com/v1.0/me/calendars/${calendarId}/events`,
eventsData,
{
headers: {
Authorization: `Bearer ${accessToken}`
}
}
);
Received Response (Partial):
{
"id": "AAMkADk5ZTYxMTBiLTI0N2ItNDkxNy04NDQ1LTU4NTM2NDUwZWJjNABGAAAAAADPDz1yPyCcQY6PeLRiiFj4BwB-un6eMt9nSr8XjQvbqJVBAAAAAAENAAB-un6eMt9nSr8XjQvbqJVBAACgoOtOAAA=",
"start": { "dateTime": "2024-05-15T22:00:00.0000000", "timeZone": "UTC" },
"end": { "dateTime": "2024-05-15T22:30:00.0000000", "timeZone": "UTC" },
...
}
Issue:
Despite specifying the timeZone
as America/New_York
in the request, the response returns event times in UTC (dateTime
fields). I expected the response to reflect the specified time zone (America/New_York
) for easier interpretation and display on the client side.
Question:
- Is there a specific reason why the event times are returned in UTC instead of the specified time zone?
- What is the recommended approach to handle time zone conversions when displaying event details to end users?
- Is there a way to configure the API request to receive event times directly in the specified time zone (
America/New_York
)?
Any guidance or insight on this matter would be greatly appreciated. Thank you!