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 :
Finance | Project Operations, Human Resources, ...
Answered

get current datetime

(0) ShareShare
ReportReport
Posted on by

What the best line of code for getting the current date time for user preferred time zone?

I have the same question (1)
  • nunomaia Profile Picture
    25 Moderator on at

    Try this 

    DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone()))

  • brianmaric Profile Picture
    on at

    That's date not datetime

  • Verified answer
    nunomaia Profile Picture
    25 Moderator on at

    DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::getSystemDateTime(), DateTimeUtil::getUserPreferredTimeZone()))

  • Suggested answer
    GirishS Profile Picture
    27,827 Moderator on at

    Hi brianmaric,

    In addition to the Nuno Maia, You can also make use of "utcNow"method in "DateTimeUtil" class.

    Thanks,

    Girish S.

  • brianmaric Profile Picture
    on at

    nice, but need the time zone applied

  • Suggested answer
    nunomaia Profile Picture
    25 Moderator on at
    [quote user="Nuno Maia"]

    DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::getSystemDateTime(), DateTimeUtil::getUserPreferredTimeZone()))

    [/quote]

    You can apply any time zone using  applyTimeZoneOffset method 

  • brianmaric Profile Picture
    on at

    is that different from this..

    DateTimeUtil::newDateTime(DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone()),

                             DateTimeUtil::getTimeNow(DateTimeUtil::getUserPreferredTimeZone()));

  • GirishS Profile Picture
    27,827 Moderator on at

    I guess both will return same output.

    Have you check that?

    Thanks

    Girish S.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 549 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans