web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Converting localTime to UTC in Pacific Time zone results in odd DST shifts

(0) ShareShare
ReportReport
Posted on by

The code below, using today as the starting date, goes back one day at a time, converting localTime to UTC time in the Pacific Time zone.  This list should result in "1 hour" offsets in March and November, but this does not seem to be the case as follows (selected results - only when a change occurred):

Circumvention: change the timezone to Arizona.

Environment: AX 2012 CU6 running on Server 2012, Client is Win7: all set with Pacific Time zone.

Any cogent theories?

2015

localDateTime: 1/25/2015 01:09:12 pm    utcTime: 1/26/2015 01:09:12 am  (January?)

localDateTime: 1/24/2015 01:09:12 pm    utcTime: 1/25/2015 02:09:12 am

 

2014

localDateTime: 11/2/2014 01:09:12 pm    utcTime: 11/3/2014 02:09:12 am  (3hrs?)

localDateTime: 11/1/2014 01:09:12 pm    utcTime: 11/1/2014 05:09:12 pm

 

localDateTime: 3/9/2014 01:09:12 pm    utcTime: 3/9/2014 05:09:12 pm  (3hrs?)

localDateTime: 3/8/2014 01:09:12 pm    utcTime: 3/9/2014 01:09:12 am

 

localDateTime: 1/26/2014 01:09:12 pm    utcTime: 1/27/2014 01:09:12 am  (January?)

localDateTime: 1/25/2014 01:09:12 pm    utcTime: 1/26/2014 02:09:12 am

 

2013

localDateTime: 11/3/2013 01:09:12 pm    utcTime: 11/4/2013 02:09:12 am  (3hrs?)

localDateTime: 11/2/2013 01:09:12 pm    utcTime: 11/2/2013 05:09:12 pm

 

localDateTime: 3/10/2013 01:09:12 pm    utcTime: 3/10/2013 05:09:12 pm  (3hrs?)

localDateTime: 3/9/2013 01:09:12 pm    utcTime: 3/10/2013 01:09:12 am

 

localDateTime: 1/19/2013 01:09:12 pm    utcTime: 1/20/2013 01:09:12 am

localDateTime: 1/18/2013 01:09:12 pm    utcTime: 1/19/2013 02:09:12 am  (January?)

 

2012

localDateTime: 11/4/2012 01:09:12 pm    utcTime: 11/5/2012 02:09:12 am   (3hrs?)

localDateTime: 11/3/2012 01:09:12 pm    utcTime: 11/3/2012 05:09:12 pm

static void JMC_LocalDateTimeToUTC(Args _args)
{

utcDateTime localDateTime;
utcDateTime utcTime;
int x;

localDateTime = DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::getSystemDateTime(), DateTimeUtil::getUserPreferredTimeZone());

for (x = 1; x < 1000; x++)
    {
    localDateTime = DateTimeUtil::addDays(localDateTime, -1);
    utcTime = DateTimeUtil::applyTimeZoneOffset(localDateTime,
    DateTimeUtil::getTimeZoneOffset(localDateTime, DateTimeUtil::getUserPreferredTimeZone()));
    info(strfmt("localDateTime: %1    utcTime: %2", localDateTime, utcTime));
    }
}


*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    I don't really follow what you're trying to achieve, nevertheless I do have some comments:

    You start with DateTimeUtil::getSystemDateTime() and apply the user preferred time zone, so it seems that you expect to get UTC time from getSystemDateTime(). But that's not the case (see documentation). You probably wanted DateTimeUtil::utcNow().

    Also, you're trying to convert local time to UTC by applying the time zone offset again, instead of removing it.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans