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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

How to have millisecond from current time ?

(0) ShareShare
ReportReport
Posted on by 397
Hi,
 
When creating log table, I want to record what time my method being called, up to millisecond.
At first I'm using this :
         System.DateTime localDateTime = DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::getSystemDateTime(), DateTimeUtil::getUserPreferredTimeZone());
         logTable.ID = localDateTime.ToString('yyyyMMdd_HHmmss.fff');
 
This is no working, so change to this:
         System.DateTime localDateTime = DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::getSystemDateTime(), DateTimeUtil::getUserPreferredTimeZone());
         logTable.ID = strFmt(/%1%2/,localDateTime.ToString('yyyyMMdd_HHmmss'), localDateTime.Millisecond);        
 
Also only give me 0 for he millisecond.
 
Some thread give idea to use WinAPI::GetTickcount(), https://community.dynamics.com/forums/thread/details/?threadid=a7ca3807-2760-4b5e-bab8-7dce477659c6, but I think it is not suitable since it is normally for calculate process time between two tickCount.
 
Thanks
I have the same question (0)
  • Layan Jwei Profile Picture
    8,158 Super User 2025 Season 2 on at
    Hi Teevo,
     
    Did u try to use this directly?
    DateTimeUtil::getSystemDateTime()
     
    Thanks,
    Layan Jweihan
  • Teevo Profile Picture
    397 on at
    Hi Layan,
     
    Meaning like the first statement ? 
              System.DateTime localDateTime = DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::getSystemDateTime(), DateTimeUtil::getUserPreferredTimeZone());
             logTable.ID = localDateTime.ToString('yyyyMMdd_HHmmss.fff');
     
     
    it's not working. or I did it wrongly ?
     
     
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,687 Super User 2025 Season 2 on at
    Hi @Teevo,
     
    if you want to get milliseconds you can use DateTimeOffset
    System.DateTimeOffset dt = System.DateTimeOffset::Now;
    int ms = dt.Millisecond;
    Best regards,
    Mohamed Amine MAHMOUDI
  • Verified answer
    Martin Dráb Profile Picture
    238,286 Most Valuable Professional on at
    AX/F&O normally doesn't work with miliseconds, therefore I don't expect that getSystemDateTime() gives you this information. System.DateTime::Now should.
  • Teevo Profile Picture
    397 on at
    Hi Martin,
     
    When testing, I always get zero if using System.DateTime::Now(). 
    I'm wondering whether I'm doing correctly or not ? 
    Here is my test :
     
    Thanks.
  • Verified answer
    Mohamed Amine Mahmoudi Profile Picture
    26,687 Super User 2025 Season 2 on at
    Hi @Teevo,
     
    Try this (it worked for me) 
    System.DateTimeOffset dt = System.DateTimeOffset::Now;
    int ms = dt.Millisecond;
    Best regards,
    Mohamed Amine MAHMOUDI
  • Teevo Profile Picture
    397 on at
    Yes,
     
    I ended up using that instead.
     
    Many thanks.
  • Martin Dráb Profile Picture
    238,286 Most Valuable Professional on at
    Teevo, the problem likely is that you're converting the System.DataTime value to utcDateTime (by using DateTimeUtil) and because utcDateTime doesn't support milliseconds, the information gets lost there.

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

News and Announcements

Season of Giving Solutions is Here!

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
Abhilash Warrier Profile Picture

Abhilash Warrier 843 Super User 2025 Season 2

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 843 Super User 2025 Season 2

#3
André Arnaud de Calavon Profile Picture

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

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans