How to split a time in hours, minutes and seconds in AX


use like we can split a date into the year, month and day part, we can do something similar for a time.  We can split the time into hours, minutes and seconds.  And the nice part: we can use the same tool for this as we use for splitting a date.  We can use the DateTimeUtil class.

Here's a short example:

staticvoid TimeSplit(Args _args)
{  
    TransDateTime   myDateTime=DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::getSystemDateTime(),Timezone::GMTPLUS0530CHENNAI_KOLKATA_MUMBAI);
int             hours;
int             minutes;
int             seconds;
    ;
    info(datetime2str(myDateTime));

    hours=DateTimeUtil::hour(myDateTime);
    minutes=DateTimeUtil::minute(myDateTime);
    seconds=DateTimeUtil::second(myDateTime);
    info(strfmt('Hours %1 - Minutes %2 - Seconds %3',int2str(hours),int2str(minutes),int2str(seconds)));
}

The DateTimeUtil class is like a kind of Swiss army knife when it comes to date and time handling.

Related Posts

Previous
Next Post »

Thanks for comments.....