Показать сообщение отдельно
Старый 07.11.2019, 14:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
a33ik: Working with utcDateTime, time conversion, daylight
Источник: http://daxonline.org/1666-working-wi...-daylight.html
==============

Some basic and advanced operations with DateTime in Dynamics AX 2012

<div>static void VKUTCToLocalDateTime(Args _args){ timeZone timeZone = timeZone::GMT_DUBLIN_EDINBURGH_LISBON_LONDON; // DateTimeUtil::getUserPreferredTimeZone(); utcDateTime standardDateTime = 2019-01-07T07:42:59, // winter time, standard daylightDateTime = 2019-07-10T10:42:59, // summer time, DST, daylight saving time localDateTime; container infoContainer; utcdatetime dayLightStartDate; utcdatetime dayLightEndDate; TimeBias standardBias; TimeBias dayLightBias; TimeZoneId timeZoneId; // Easy conversion to local time // from UTC to GMT/BST (GB/UK/London); localDateTime = DateTimeUtil::applyTimeZoneOffset(standardDateTime, timeZone); localDateTime = DateTimeUtil::applyTimeZoneOffset(daylightDateTime, timeZone); // Hard way conversion daylightDateTime to local time, but with more control // Get timezone information container infoContainer = DateTimeUtil::populateTimeZoneInfo(DateTimeUtil::year(daylightDateTime), timeZone); dayLightStartDate = conPeek(infoContainer, 1); dayLightEndDate = conPeek(infoContainer, 2); standardBias = conPeek(infoContainer, 3); dayLightBias = conPeek(infoContainer, 4); // substract timebias // https://stackoverflow.com/questions/...e-in-local-dst localDateTime = DateTimeUtil::addMinutes(daylightDateTime, -standardBias); if (daylightDateTime >= dayLightStartDate && daylightDateTime