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
If you want to check on how to convert UTC time to local time in Dynamics 365/ Model driven apps, check this blog post.
- 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!
Debajit Dutta
(Dynamics MVP)
For consultation/ corporate training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com
Our product offerings:
CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)
Notes Manager (https://debajmecrm.com/add-metadata-to-your-notes-and-attachments-in-dynamics-notes-metadata-manager-from-xrmforyou-com/)
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)
Discover more from Debajit's Power Apps & Dynamics 365 Blog
Subscribe to get the latest posts sent to your email.