web
You’re offline. This is a read only version of the page.
close
Skip to main content
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)
  • GirishS Profile Picture
    27,825 Moderator on at
    RE: get current datetime

    I guess both will return same output.

    Have you check that?

    Thanks

    Girish S.

  • brianmaric Profile Picture
    on at
    RE: get current datetime

    is that different from this..

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

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

  • Suggested answer
    nunomaia Profile Picture
    23 Moderator on at
    RE: get current datetime
    [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
    RE: get current datetime

    nice, but need the time zone applied

  • Suggested answer
    GirishS Profile Picture
    27,825 Moderator on at
    RE: get current datetime

    Hi brianmaric,

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

    Thanks,

    Girish S.

  • Verified answer
    nunomaia Profile Picture
    23 Moderator on at
    RE: get current datetime

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

  • brianmaric Profile Picture
    on at
    RE: get current datetime

    That's date not datetime

  • nunomaia Profile Picture
    23 Moderator on at
    RE: get current datetime

    Try this 

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

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 1,072

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 829 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans