Get current system time in AX

You can use the x++ builtin method timeNow() to get the current system time in Microsoft Dynamics AX.

TimeInMS currentTime;
currentTime = timeNow();

If you want to convert the time to string then it can be easily achieve by time2str() method, which follows as.

time2str( int time, int separator, int format);

whereas following criteria will be very helpfully to show the time in info box.

Code:
TimeInMS currentTime;
str timeToStr;

currentTime = timeNow();
timeToStr = time2str(currentTime,1,1);
info(strFmt('Current system time is: %1',timeToStr));

Output:
// Current system time is: 07:53:08

Now, if you need complete time with a.m. and p.m. then change the format parameter in time2str() method.
e.g.

Code:
TimeInMS currentTime;
str timeToStr;

currentTime = timeNow();
timeToStr = time2str(currentTime,1,2);
info(strFmt('Current system time is: %1',timeToStr));

Output:
// Current system time is: 07:53:08 a.m

Hope this help you guys, Thanks for reading this blog.







Comments