web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Datetime format in javascript gives me UTC time of datetime field

(0) ShareShare
ReportReport
Posted on by 836

Hello,

I need to read Date value of one DateTime field in my Dynamics CRM Form using JavaScript.

I am able to read the value but it is not exactly same what I can see in CRM.Date t

In CRM Form, selected value is: 11 Nov 2020 8:00am

JavaScript Code return value as 11 Nov 2020 different time, as per UTC.

How do i make JS read write value

I have the same question (0)
  • Suggested answer
    Fubar Profile Picture
    2,761 on at

    This is a general JavaScript date-time issue when dealing with date objects and UTC and browser local time.  

    Depending on exactly what you are wanting to do the answer may be slightly different, and the methods may be different, but on a Date object  .toLocaleDateString()  or .toLocaleDateString("<country code>") if you want it in a specific country timezone  etc (also a similar method exists exists for the time component). 

    developer.mozilla.org/.../toLocaleDateString

  • Suggested answer
    Inogic Profile Picture
    682 on at

    Hi Ravi,

    You can use getTimeZoneOffsetMinutes function from global context as below to get the correct date and time value. 

    var dateTimeFieldValue  = Xrm.Page.getAttribute("FieldName").getValue()

    var utcDate = new Date(dateTimeFieldValue.getUTCFullYear() , dateTimeFieldValue.getUTCMonth() , dateTimeFieldValue.getUTCDate(), dateTimeFieldValue.getUTCHours(), dateTimeFieldValue.getUTCMinutes(), dateTimeFieldValue.getUTCSeconds() ,dateTimeFieldValue.getUTCMilliseconds());

    var correctFieldDateTimeValue = new Date(utcDate.setMinutes(utcDate.getMinutes() + Xrm.Utility.getGlobalContext().userSettings.getTimeZoneOffsetMinutes()));

    Hope this helps!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 170 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 70

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans