
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)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.