Monday, July 3, 2023

How to convert a UTC DateTime value to a user-specific timezone in X++

 public static void main(Args _args)

{

    TransDateTime utcDateTime, localDateTime;

    utcDateTime = DateTimeUtil::utcNow(); // gets the current UTC date and time


    // convert UTC time to user time zone

    localDateTime = DateTimeUtil::applyTimeZoneOffset(

        utcDateTime,

        DateTimeUtil::getTimeZoneOffsetForUser()

    );


    info(strFmt("UTC DateTime: %1", utcDateTime));

    info(strFmt("Local DateTime: %1", localDateTime));

}