I am working with a SharePoint Online server in another timezone. I am attempting to retrieve the values from a List with a DateTime field. Using CSOM I am able to retrieve the DateTime value stored in the list, however they are stored with UTC + Daylight savings in the timezone of the SP Server location. How can I change the Timezone of my DateTime object while keeping the value the same? (Example: Change 03:00 PM PST to 03:00 PM EST).
For reference I am already grabbing the SharePoint server TimeZone by using ClientContext.Web.RegionalSettings.TimeZone
Edit1:
Code:
#region Get Sharepoint Server Timezone Offset
var rS = context.Web.RegionalSettings;
context.Load(rS);
var sPtZ = rS.TimeZone;
context.Load(sPtZ);
context.ExecuteQuery();
ReadOnlyCollection<TimeZoneInfo> tZs = TimeZoneInfo.GetSystemTimeZones();
string tZ = rS.TimeZone.Description;
if (tZ.Contains(" and "))
{
tZ = tZ.Replace(" and ", " & ");
}
#endregion
#region Write List Values to AF
foreach (ListItem item in spCollection)
{
AFElement well = vendor.Wells.First(x => x.Name == (item.FieldValues["Well_x0020_Name"].ToString()));
if (well != null)
{
DateTime dT = DateTime.Parse(item.FieldValues["efwy"].ToString());
DateTime utc = TimeZoneInfo.ConvertTimeToUtc(dT, tZs.First(x => x.Id == "UTC")).ToLocalTime();
AFValue afV = new AFValue((double)item.FieldValues["lbpl"], new AFTime(DateTime.Parse(item.FieldValues["efwy"].ToString()).ToLocalTime()));
//well.Attributes["Manual Input - Choke Size"].SetValue(afV);
//well.Database.ApplyChanges();
//well.Database.CheckIn();
}
//Else leave item in list
}
context.ExecuteQuery();
#endregion
rS.Timezone.Description has a value of (UTC-08:00) Pacific Time (US and Canada)
The actual SharePoint List value is 12/3/2019 5:00 AM
My dT value is {12/3/2019 1:00:00 PM}
This tells me that SharePoint is returning the value in UTC time.
However, after setting that value as UTC then to local time on DateTime "utc" its showing 7:00AM.