Get current time in ax x++

Hi,

Get current time in ax x++

static void TimeJob4(Args _args)
{
    timeOfDay theTime = timeNow();
    ;
    info( time2Str(theTime, TimeSeparator::Colon, TimeFormat::AMPM) );
}

/**
Message (04:33:56 pm)
04:33:56 pm
**/

Ref
Ref1

1)date
static void date2StrExample(Args _arg)
{
    date d = today();
    str s;
    ;
    s = date2Str(d, 123, 2, -1, 2, -1, 2);
    print "Today's date is " + s;
    pause;
2) time
static void timeNowExample(Args _arg)
{
    int i;
    ;
    i = timeNow();
    print "The number of seconds since midnight is " + int2Str(i);
    pause;
}

3) use Time to str function to convert time in second form your desire format.
// Returns the text string 05:01:38.
time2Str(18098,1,1);
// Returns the text string 05:01:38 am.
time2Str(18098,1,2);
// Returns the text string 05 01 39.
time2Str(18099,3,1);
// Returns the text string 05/01/39 am.
time2Str(18099,5,2);
 
4) finally using 1,2 & 3 you can get date&time.

Comments