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 (0)
  • 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
    18 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
    18 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
    18 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…

Mansi Soni – Community Spotlight

We are honored to recognize Mansi Soni as our August 2025 Community…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

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

#1
Sohaib Cheema Profile Picture

Sohaib Cheema 665 User Group Leader

#2
Martin Dráb Profile Picture

Martin Dráb 595 Most Valuable Professional

#3
Yng Lih Profile Picture

Yng Lih 558

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans