let eventDate = new Date('2021-09-01T17:00:00Z'); let eventStart = new Date(Date.UTC(eventDate.getUTCFullYear(), eventDate.getMonth(), eventDate.getUTCDate(), eventDate.getUTCHours(), eventDate.getUTCMinutes(), eventDate.getUTCSeconds())); let eventEnd = new Date(eventStart.getTime() + (60 * 60 * 1000)); //default event duration is 1 hour
let event = { 'summary': 'Test Event', 'location': 'Test Location', 'description': 'Test Description', 'start': { 'dateTime': eventStart.toISOString(), 'timeZone': 'UTC' }, 'end': { 'dateTime': eventEnd.toISOString(), 'timeZone': 'UTC' } };
gapi.load('client:auth2', () => { gapi.client.init({ /* API key and other options / }).then(() => { gapi.client.load('calendar', 'v3', () => { gapi.client.calendar.events.insert({ 'calendarId': 'primary', 'resource': event }).then((response) => { / Handle the response */ }); }); }); });
这样,您应该可以使用Angular 12正确地将事件添加到Google日历中,并显示正确的日期时间。