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

Announcements

No record found.

News and Announcements icon
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
    748 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 189 Super User 2026 Season 1

#2
CU11031447-0 Profile Picture

CU11031447-0 100

#3
NeerajPawar Profile Picture

NeerajPawar 66

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans