I came across a weired problem with the
UTCToLocalTime functions of the
TimeZone class (C#, CSOM v14.0.4762.1000).
The results are just completely wrong. I couldn't find any other page about this error, so here is what I got:
// definition of site and clientContext are omitted Microsoft.SharePoint.Client.TimeZone timeZone = site.RegionalSettings.TimeZone; clientContext.Load(timeZone); clientContext.ExecuteQuery();
At this point
timeZone.Description equals to "(UTC+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna", which is correct in my case. When I issue the following lines however, which both are supposed to equal to the current UTC time, the results are not equal at all.
DateTime utc1 = timeZone.LocalTimeToUTC(DateTime.Now).Value; // 01/01/0001 00:00:00 DateTime utc2 = DateTime.UtcNow; // 14/06/2018 21:30:56
The value of
utc1 just makes no sense at all. I've checked that
DateTime.Now gives the correct input, which it does.
LocalTimeToUTC is explicitly taking
UTCToLocalTime I'm getting the same issues.
Does anybody know what's going wrong? Is it me or is it Microsoft?