Thursday, December 21, 2017

AX, X++ - How get time offset to UTC zone time

Example returns offset in hours to UTC time.
UtcDateTime dt_DateTime_Create;
int iUTCOffset;

dt_DateTime_Create = DateTimeUtil::getSystemDateTime();
    
iUTCOffset = DateTimeUtil::getTimeZoneOffset( dt_DateTime_Create, 
               Timezone::GMT_DUBLIN_EDINBURGH_LISBON_LONDON ) / 60;
info( int2str( iUTCOffset ) );
    
iUTCOffset = DateTimeUtil::getTimeZoneOffset( dt_DateTime_Create, 
               Timezone::GMTPLUS0100_AMSTERDAM_BERLIN_BERN_ROME ) / 60;
info( int2str( iUTCOffset ) );
    
iUTCOffset = DateTimeUtil::getTimeZoneOffset( dt_DateTime_Create, 
               Timezone::GMTPLUS0800PERTH ) / 60;
info( int2str( iUTCOffset ) );
Output (Prague, Berlin):
0
1
8

No comments:

Post a Comment