Help with date time graph posting to sharepoint in utc time
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);
}