I have the following CSOM code inside my C# console application:-

var regionalSettings = context.Web.RegionalSettings;
var localDueDate = regionalSettings.TimeZone.UTCToLocalTime(itemversion.Created).Value;

but the localDueDate will always be equal to 01/01/0001 00:00:00.. my site collection regional setting is :-

enter image description here

so i though the above code will add 4 hours to the DateTime.. so can anyone advice what is wrong with my code? in my case the itemversion.Created equal 14/10/2020 13:14:11, but var localDueDate = regionalSettings.TimeZone.UTCToLocalTime(itemversion.Created).Value; will return 01/01/0001 00:00:00!!


01/01/0001 00:00:00 is a blank date. You need to add context.ExecuteQuery() after regionalSettings.TimeZone.UTCToLocalTime(itemversion.Created).Value to submit the convertion operation.

        // timezone
        var spTimeZone = context.Web.RegionalSettings.TimeZone;            



        var orginaldate = DateTime.ParseExact("14/10/2020 13:14:11","dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture);          
        ClientResult<DateTime> cr = spTimeZone.UTCToLocalTime(orginaldate);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.