UtcTimeFromLocalTime – A function introduced in Dynamics 365 to allow you to convert time in any timezone to the corresponding UTC time. It has couple of parameters
- LocalTime – DateTime object to set the local time
- TimeZoneCode – Timezonecode of type integer.
So let’s see how we can put this in action
UtcTimeFromLocalTimeRequest request = new UtcTimeFromLocalTimeRequest();
request.LocalTime = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Unspecified);
request.TimeZoneCode = 190; // this is the timezone code IST
UtcTimeFromLocalTimeResponse response = (UtcTimeFromLocalTimeResponse)service.Execute(request);
var utcDateTime = response.UtcTime;
Observe how I have passed the LocalTime value. Please note that if you want to pass the current date time object, don’t use DateTime.Now as it may give undesirable results. Pass the datetime value using DateTIme.SpecifyKind as done in the above code.
If you want to pass some specific date time you can construct a datetime object like below.
request.LocalTime = new DateTime(2020,5,29,21,30,0);
Hope this helps!
Our product offerings:
CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)
Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)
Record Cloner for Dynamics 365 (http://www.xrmforyou.com/record-cloner.html)