Help with date time graph posting to sharepoint in utc time

Soi, Eric 1 Reputation point
2022-03-07T22:21:10.877+00:00

Systems guy here who inherited this app from programmer who left company. New to programming so any help would be greatly appreciated. Program was working fine till around Dec. Shows correct time to email and db, but when posting to sharepoint time is in utc.

if (!string.IsNullOrEmpty(spoSiteName) && !string.IsNullOrEmpty(spoCalendarListName))
{
bool boolAllDay1 = Convert.ToBoolean(allDay1);
DateTime startDate1Date = Convert.ToDateTime(startDate1);
DateTime endDate1Date = Convert.ToDateTime(endDate1);
DateTime startTime1Time = !boolAllDay1 ? Convert.ToDateTime(startTime1) : Convert.ToDateTime(@"12:00:00 AM");
DateTime endTime1Time = !boolAllDay1 ? Convert.ToDateTime(endTime1) : Convert.ToDateTime(@"11:59:59 PM");

                string startDate1String = string.Format("{0}T{1}", (boolAllDay1 ? startDate1Date.AddDays(1) : startDate1Date).ToString("yyyy-MM-dd"), startTime1Time.ToString("HH:mm:ss"));
                string endDate1String = string.Format("{0}T{1}", endDate1Date.ToString("yyyy-MM-dd"), endTime1Time.ToString("HH:mm:ss"));

                Microsoft.Graph.ListItem event1 = new Microsoft.Graph.ListItem
                {
                    Fields = new Microsoft.Graph.FieldValueSet
                    {
                        AdditionalData = new Dictionary<string, object> {
                { "ContentType", "Event" },
                { "Title", eventTitle + @" (" + eventType + @")" },
                { "Category", category },
                { "Description", comments },
                { "EventDate",startDate1String},
                { "EndDate", endDate1String },
                { "fAllDayEvent", boolAllDay1 }
            }
                    }
                };

                SaveSPOCalendarEvent(siteId: siteId, calendarId: calendarId, spoCalendarEvent: event1, requestId: requestId, page: page, siteName:spoSiteName,calendarName:spoCalendarListName);

                if (!string.IsNullOrEmpty(startDate2) && !string.IsNullOrEmpty(endDate2))
                {
                    bool boolAllDay2 = Convert.ToBoolean(allDay2);
                    DateTime startDate2Date = Convert.ToDateTime(startDate2);
                    DateTime endDate2Date = Convert.ToDateTime(endDate2);
                    DateTime startTime2Time = !boolAllDay2 ? Convert.ToDateTime(startTime2) : Convert.ToDateTime(@"12:00:00 AM");
                    DateTime endTime2Time = !boolAllDay2 ? Convert.ToDateTime(endTime2) : Convert.ToDateTime(@"11:59:59 PM");

                    string startDate2String = string.Format("{0}T{1}", (boolAllDay2 ? startDate2Date.AddDays(1) : startDate2Date).ToString("yyyy-MM-dd"), startTime2Time.ToString("HH:mm:ss"));
                    string endDate2String = string.Format("{0}T{1}", endDate2Date.ToString("yyyy-MM-dd"), endTime2Time.ToString("HH:mm:ss"));

                    Microsoft.Graph.ListItem event2 = new Microsoft.Graph.ListItem
                    {
                        Fields = new Microsoft.Graph.FieldValueSet
                        {
                            AdditionalData = new Dictionary<string, object> {
                { "ContentType", "Event" },
                { "Title", eventTitle + @" (" + eventType + @")" },
                { "Category", category },
                { "Description", comments },
                { "EventDate", startDate2String },
                { "EndDate", endDate2String },
                { "fAllDayEvent", boolAllDay2 }
            }
                        }
                    };
                    SaveSPOCalendarEvent(siteId: siteId, calendarId: calendarId, spoCalendarEvent: event2, requestId: requestId, page: page, siteName: spoSiteName, calendarName: spoCalendarListName);
                }
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,446 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,300 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,648 questions
{count} votes